<!DOCTYPE html>
<?php
$username = $_SESSION['User_Name'];
require_once('convert_marathi.php');
$no=$_GET['no'];
$flag=$_REQUEST['flag'];

$deptid=$_REQUEST['deptid'];
########################################### Department Wise Report To Tapal User #######################################
if($no==2)
{
	include('dashboard_tapal.php');	
	
	?>
	<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<script type="text/javascript">     
	function PrintDiv() {    
	var divToPrint = document.getElementById('divToPrint');
	var popupWin = window.open('', '_blank', 'width=600,height=600');
	popupWin.document.open();
	popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
	popupWin.document.close();
	}
	</script>
	<script src="tableToExcel.js"></script>
	</head>
	<body>
	<div class="mainwrapper">   
		<div class="rightpanel">
            <ul class="breadcrumbs">
				<li><a href=""><i class="iconfa-home"></i></a> <span class="separator"></span></li>
				<li><a href="">विभागानुसार रिपोर्ट्स </a> <span class="separator"></span></li>
				<li></li>
			</ul>
			<div class="pageheader">
				<div class="pageicon"><span class="iconfa-table"></span></div>
					<div class="pagetitle">
					<h1>विभागानुसार रिपोर्ट्स </h1>
					
				</div>
			</div><!--pageheader-->
			<?php 		
			######################################### Display Counter ######################################
			if($deptid=="" && $no==2)	
				{  ?>
					<div class="maincontent">
						<div class="maincontentinner">
							<h4 class="widgettitle">विभागानुसार रिपोर्ट्स </h4>
							<form method="post" action="">
								<?php
								convert_marathi();
								echo "<form name='dept_sandarbh' 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='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 method='post' action=''>";
							$date123	= $_POST['start_date'];
							$date1	= date('Y-m-d',strtotime($date123));
							$date223	= $_POST['end_date'];
							$date2	= date('Y-m-d',strtotime($date223));
							//$date22	= date('d-m-Y',strtotime($date2));
							if($date123==''&& $date223=='')
							{
							
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id = $date1;
								$id1= $date2;
								$qre=("SELECT t.dept_id_from,dm.desk_flag, dm.dept_nm, COUNT(*) AS TOTAL 
								FROM tapal_to_dpt_transaction t,department_master dm
								where t.dept_id_from=dm.dept_id 
								AND t.returned_choice=''
								GROUP BY dept_nm");
								$rsut=mysql_query($qre) or die("sssssss".mysql_error());
								
							}
							else{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id = $date1;
								$id1= $date2;
								$qre=("SELECT t.dept_id_from, dm.desk_flag, dm.dept_nm, COUNT(*) AS TOTAL 
								FROM tapal_to_dpt_transaction t,department_master dm 
								where t.dept_id_from=dm.dept_id 
								AND t.returned_choice='' and t.dpt_ltr_rec_dt BETWEEN '$date1' and '$date2' 
								GROUP BY dept_nm");
								$rsut=mysql_query($qre) or die("sssssss".mysql_error());
							}
								echo "<table id='dyntable' class='table table-bordered border'>
								<thead>
								<tr>
								<th class='head0 center' style='width:160px;'>विभागाचे नाव </th>
								<th class='head1 center'>एकूण </th>
								</tr>
								</thead>";
								while($rws = mysql_fetch_array($rsut))
								{
									$deptid=$rws['dept_id_from'];
									$deskflag=$rws['desk_flag'];
									
									if($deskflag=='Y' || $deskflag=='y' )
									{
									?>
										<tbody>
										<tr class="gradeX">
										<?php 
										echo "<td><a href='report_dptwise.php?deptid=$deptid&no=2'>".$rws['dept_nm']."</a></td><td>". $rws['TOTAL']."</td> </tr>";    
									}
									else if($deskflag=='N' || $deskflag=='n' )
									{
									?>
										<tbody>
										<tr class="gradeX">
										<?php 
										echo "<td><a href='report_dptwise.php?flag=n&deptid=$deptid&no=2'>".$rws['dept_nm']."</a></td><td>". $rws['TOTAL']."</td> </tr>";    
									}
								}?>
								</tbody>
							</table>
				
								
								<?php
								
								echo "<div id='divToPrint' style='display:none;'>
								<table id='export' border='1px' style='margin-left:50px;'>";
								convert_marathi();
								if($date123==''&& $date223=='')
								{
								
									$id = $date1;
									$id1= $date2;
									$qre=("SELECT t.dept_id_from,dm.desk_flag, dm.dept_nm, COUNT(*) AS TOTAL 
									FROM tapal_to_dpt_transaction t,department_master dm
									where t.dept_id_from=dm.dept_id 
									AND t.returned_choice=''
									GROUP BY dept_nm");
									$rsut=mysql_query($qre) or die("sssssss".mysql_error());
									
								}
								else
								{
									$id = $date1;
									$id1= $date2;
									$qre=("SELECT t.dept_id_from, dm.desk_flag, dm.dept_nm, COUNT(*) AS TOTAL 
									FROM tapal_to_dpt_transaction t,department_master dm 
									where t.dept_id_from=dm.dept_id 
									AND t.returned_choice='' and t.dpt_ltr_rec_dt BETWEEN '$date1' and '$date2' 
									GROUP BY dept_nm");
									$rsut=mysql_query($qre) or die("sssssss".mysql_error());
								}
								
								echo "<center><h2>पोलीस अधिक्षक <br> कार्यालय <br>जि.रायगड<h2></center>";
								echo "<table id='export' border='1px' style='text-align:center; margin-left:550px;' >";
								echo "<tr><td colspan='9'><center> विभागानुसार रिपोर्ट्स  <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
									
								echo "<tr>
									<th>विभागाचे नाव </th>
									<th>एकूण </th>
								</tr>";
								while($rws = mysql_fetch_array($rsut))
								{
									$deptid=$rws['dept_id_from'];
									echo "<tr>";
									echo "<td>".$rws['dept_nm']."</td><td>". $rws['TOTAL']."</td> </tr>";                
								}
							echo "</table></div>";
			} 
				####################################### End Of Display Counter #########################################
				
				######################################### Display Details #########################################
			else if( $deptid != "" && $no==2)
			{	
				convert_marathi();
				$m=mysql_query("Select dept_nm from department_master where dept_id='$deptid'");
				$mm=mysql_fetch_array($m);	
				
				?>
				<div class="maincontent">
					<div class="maincontentinner" >
						<h4 class="widgettitle"><?php echo $mm['dept_nm'];?> रिपोर्ट्स</h4>		   
							<form method="post" action="">
								<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
								<table>
									<tr>
										<td align="center"><label style="width:110px;">Start date</label></td>
										<td align="center"><input type="text" name="start_date" class="input-small"/></td>
										<td align="center"><label style="width:110px;">End Date</label></td>
										<td align="center"><input type="text" name="end_date" class="input-small"/></td>
									</tr>
									<tr>
										<td colspan="6">
										<div align="center">
											<input type="submit" onClick="return sadyasthitiDates()" name="ok" value="GO"/>
											<input type="reset" value="CLEAR" name="clear"/>
										</div>
										</td>
									</tr>
								</table>
								</div>
							</form>
							<form action="" method="post">
								<?php
								convert_marathi();	
								$date123	= $_POST['start_date'];
								$date1	= date('Y-m-d',strtotime($date123));
								$date223	= $_POST['end_date'];
								$date2	= date('Y-m-d',strtotime($date223));
								//$date22	= date('d-m-Y',strtotime($date2));
								
						if($flag=='')
						{
								if($date123==''&& $date223=='')
								{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									/*$result222=mysql_query("SELECT de.desk_ltr_id, 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.desk_approval, t.status,t.dpt_inword_no, t.sent_to_desk_dt ,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.priority_days,  i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, di.dispatched_to,di.dept_id_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.dept_id_from='$deptid'
									ORDER BY i.ltr_inword_no DESC") or die("sdfdfds".mysql_error()); */
									
									//accpeted by dept but deskid=0 or desk_apprval=pending
									$result222=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.desk_approval,t.status, 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.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 (t.desk_id='0' OR t.desk_approval='pending')
									AND t.returned_choice=''
									ORDER BY i.ltr_inword_no DESC") OR die("aabbhhaa".mysql_error());
									 
									//accpeted by desk and ltrstatus!=closed
									$result2221=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.desk_approval,t.status, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, 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'
									ORDER BY i.ltr_inword_no DESC") OR die("aabbhhaa".mysql_error());
								}
								else{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=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.desk_approval,t.status, 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.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 (t.desk_id='0' OR t.desk_approval='pending') AND t.returned_choice=''
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
									
									$result2221=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.desk_approval,t.status, 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,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());
								}
								$count10=mysql_num_rows($result222);
			
								echo "<table id='dyntable' class='table table-bordered'>
								<thead> 
								<tr>
								<th class='head0 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class='head1 center'>संदर्भ <br>प्राप्त_दिनांक</th>
								<th class='head1 center'>विभाग<br>प्राप्त_दिनांक</th>
								<th class='head0 center'>विषय</th>
								<th class='head1 center'>कोणाकडून प्राप्त झाला</th>";
								//echo "<th class='head0 center'>प्राधान्य दिवस </th>";
								echo "<th class='head1 center'>डेस्कला पाठवले <br>डेस्कला पाठवलेली_दिनांक</th>
								<th class='head1 center'> केलेली <br>कार्यवाही </th>
								<th class='head0 center'>पत्राची स्थिती </th>
								</tr>
								</thead>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$desk=$test['desk_id'];
									
									//closed lettr
									$ltrinward=$test['ltr_inword_no'];
									$deskidfrom=$test['desk_id_from'];
									
									if($test['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>";
									}
									
									convert_marathi();
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//echo $desknm."bbbbbbb";
									
									$qry091="Select desk_nm from desk_master where desk_id='$desk'";
									$rs091=mysql_query($qry091) or die("aass".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									$desknm1=$rw091['desk_nm'];
									
									
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									
									///////////////////////////////////////////////////////////
									
									 if($test['desk_approval']=='pending')
									{
										
										echo "<td class='center'><font color='red'>".$desknm1."<br>डेस्कने स्वीकारणे बाकी </font></td> ";
									}
									else if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'>डेस्कला पाठवलेले नाही</font> </td> ";
									}
									else if($desknm!='')
									{
										echo "<td class='center'><a href='report_dpt_deskwise.php?no=2&deskid=$deskid&deptid=$deptid'>".$desknm."</a>";
									}
									
									echo "<br>".$dis_date."</font></td>";
									/////////////////// Action Taken //////////////////////////////
							/*
									if($result['rtn_to_dsk']=='')
									{
										$returnto=$mm['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($test['ltr_status']=='')
									{
										echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी </font></td> ";
									}
									else if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}*/
									
									echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी </font></td> ";
									/////////////////////////////////////////////////////////////////
									$depti=$test['dept_id_to'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									
									if($test['ltr_approval']=='transferred')
									{
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$dept['dept_nm']."</td>";
									}
									else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='updated' )
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='closed')
									{
										echo "<td class='center'>".$test['desk_approval']."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									echo "</tr>";
								}
								//mysql_close();
								while($test = mysql_fetch_array($result2221))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$desk=$test['desk_id'];
									
									//closed lettr
									$ltrinward=$test['ltr_inword_no'];
									$deskidfrom=$test['desk_id_from'];
									
									if($test['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'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									convert_marathi();
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//echo $desknm."bbbbbbb";
									
									$qry091="Select desk_nm from desk_master where desk_id='$desk'";
									$rs091=mysql_query($qry091) or die("aass".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									$desknm1=$rw091['desk_nm'];
									//echo $desknm1['desk_nm'];
									///////////////////////////////////////////////////////////
									if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'><a href='report_dpt_deskwise.php?no=2&deskid=$deskid&deptid=$deptid'>".$desknm."</a><br>".$dis_date."</td>";
									}
									else if($test['desk_approval']=='pending')
									{
										
										echo "<td class='center'>".$desknm1['desk_nm']."<br><font color='red'>डेस्कने स्वीकारणे बाकी </font></td> ";
									}
									else if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'>डेस्कला पाठवलेले नाही</font> </td> ";
									}
									else if($desknm!='')
									{
										echo "<td class='center'><a href='report_dpt_deskwise.php?no=2&deskid=$deskid&deptid=$deptid'>".$desknm."</a>";
									}
									
									echo "<br>".$dis_date."</font></td>";
									/////////////////// Action Taken //////////////////////////////
							
									if($result['rtn_to_dsk']=='')
									{
										$returnto=$mm['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($test['ltr_status']=='')
									{
										echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी </font></td> ";
									}
									else if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									/////////////////////////////////////////////////////////////////
									$depti=$test['dept_id_to'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									
									if($test['ltr_approval']=='transferred')
									{
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$dept['dept_nm']."</td>";
									}
									else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='updated' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									
									else
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									echo "</tr>";
								}
								echo"   </tbody></table>";
						
							echo "<div id='divToPrint' style='display:none;'>
								<table id='export' border='1px' style='margin-left:150px;'>
								<tr><td colspan='8'><center>".$mm['dept_nm']."रिपोर्ट्स <br> दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								convert_marathi();
								echo "<center><h2>पोलीस अधिक्षक <br> कार्यालय <br>जि.रायगड<h2></center>";
								//GROUP BY incoming_letters_transaction.ltr_id				
								if($date123==''&& $date223=='')
								{
									$id1 = $date1;
									$id2= $date2;
									
									//accpeted by dept but deskid=0 or desk_apprval=pending
									$result222=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.desk_approval,t.status, 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, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt,di.dept_id_to, 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.desk_id='0' OR t.desk_approval='pending')
									AND t.returned_choice=''
									ORDER BY i.ltr_inword_no DESC") OR die("aabbhhaa".mysql_error());
									 
									//accpeted by desk and ltrstatus!=closed
									$result2221=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.desk_approval,t.status, 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,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'
									ORDER BY i.ltr_inword_no DESC") OR die("aabbhhaa".mysql_error());
								}
								else{
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=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.desk_approval,t.status, 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, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt,di.dept_id_to, 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.desk_id='0' OR t.desk_approval='pending') AND t.returned_choice=''
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
									
									$result2221=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.desk_approval,t.status, 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,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());
								}
								$count10=mysql_num_rows($result222);
			
								echo "
								<tr>
								<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ <br>प्राप्त_दिनांक</th>
								<th>विभाग<br>प्राप्त_दिनांक</th>
								<th>विषय</th>
								<th>कोणाकडून प्राप्त झाला</th>";
								//echo "<th>प्राधान्य दिवस </th>";
								echo "<th>डेस्कला पाठवले <br>डेस्कला पाठवलेली_दिनांक</th>
								<th> केलेली <br>कार्यवाही </th>
								<th>पत्राची स्थिती </th>
								</tr>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$desk=$test['desk_id'];
									
									//closed lettr
									$ltrinward=$test['ltr_inword_no'];
									$deskidfrom=$test['desk_id_from'];
									
									if($test['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'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									convert_marathi();
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//echo $desknm."bbbbbbb";
									
									$qry091="Select desk_nm from desk_master where desk_id='$desk'";
									$rs091=mysql_query($qry091) or die("aass".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									$desknm1=$rw091['desk_nm'];
									//echo $desknm1['desk_nm'];
									///////////////////////////////////////////////////////////
									 if($test['desk_approval']=='pending')
									{
										
										echo "<td class='center'>".$desknm1."<br>डेस्कने स्वीकारणे बाकी </td> ";
									}
									else if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'>डेस्कला पाठवलेले नाही </td> ";
									}
									else if($desknm!='')
									{
										echo "<td class='center'>".$desknm."";
									}
									
									echo "<br>".$dis_date."</font></td>";
									/////////////////// Action Taken //////////////////////////////
							/*
									if($result['rtn_to_dsk']=='')
									{
										$returnto=$mm['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($test['ltr_status']=='')
									{
										echo "<td class='center'>कार्यवाही करणे बाकी </td> ";
									}
									else if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									} */
									echo "<td class='center'>कार्यवाही करणे बाकी </td> ";
									/////////////////////////////////////////////////////////////////
									$depti=$test['dept_id_to'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									
									if($test['ltr_approval']=='transferred')
									{
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$dept['dept_nm']."</td>";
									}
									else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='updated' )
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='closed')
									{
										echo "<td class='center'>".$test['desk_approval']."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									echo "</tr>";
								}
								//mysql_close();
								while($test = mysql_fetch_array($result2221))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$desk=$test['desk_id'];
									
									//closed lettr
									$ltrinward=$test['ltr_inword_no'];
									$deskidfrom=$test['desk_id_from'];
									
									if($test['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'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									convert_marathi();
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//echo $desknm."bbbbbbb";
									
									$qry091="Select desk_nm from desk_master where desk_id='$desk'";
									$rs091=mysql_query($qry091) or die("aass".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									$desknm1=$rw091['desk_nm'];
									//echo $desknm1['desk_nm'];
									///////////////////////////////////////////////////////////
									if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>".$desknm."<br>".$dis_date."</td>";
									}
									else if($test['desk_approval']=='pending')
									{
										
										echo "<td class='center'>".$desknm1['desk_nm']."<br>डेस्कने स्वीकारणे बाकी </td> ";
									}
									else if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'>डेस्कला पाठवलेले नाही </td> ";
									}
									else if($desknm!='')
									{
										echo "<td class='center'>".$desknm."";
									}
									
									echo "<br>".$dis_date."</font></td>";
									/////////////////// Action Taken //////////////////////////////
							
									if($result['rtn_to_dsk']=='')
									{
										$returnto=$mm['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($test['ltr_status']=='')
									{
										echo "<td class='center'>कार्यवाही करणे बाकी </td> ";
									}
									else if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									/////////////////////////////////////////////////////////////////
									$depti=$test['dept_id_to'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									
									if($test['ltr_approval']=='transferred')
									{
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$dept['dept_nm']."</td>";
									}
									else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='updated' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									
									else
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									echo "</tr>";
								}
							}
							
						else if($flag=='n')
						{
								if($date123==''&& $date223=='')
								{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=mysql_query("SELECT  t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken,i.priority_days,  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, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
									FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
									LEFT OUTER JOIN dispatched_transaction di ON di.dpt_inword_no = t.dpt_inword_no
									WHERE  t.dept_id_from='$deptid'
									AND t.returned_choice=''
									ORDER BY i.ltr_inword_no DESC") or die("sdfdfds".mysql_error());
									
								}
								else{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=mysql_query("SELECT  t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken,i.priority_days, 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, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
									FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
									LEFT OUTER JOIN dispatched_transaction di ON di.dpt_inword_no = t.dpt_inword_no
									WHERE t.ltr_id=i.ltr_id 
									AND  t.dept_id_from='$deptid' 
									AND t.returned_choice=''
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
								}
								$count10=mysql_num_rows($result222);
			
								echo "<table id='dyntable' class='table table-bordered'>
								<thead> 
								<tr>
								<th class='head0 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class='head1 center'>संदर्भ <br>प्राप्त_दिनांक</th>
								<th class='head1 center'>विभाग<br>प्राप्त_दिनांक</th>
								<th class='head0 center'>विषय</th>
								<th class='head1 center'>कोणाकडून प्राप्त झाला </th>";
								//echo "<th class='head0 center'>प्राधान्य दिवस </th>";
								echo "<th class='head0 center'> केलेली <br>कार्यवाही </th>
								<th class='head0 center'>पत्राची स्थिती </th>
								</tr>
								</thead>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									/////////////////////////////
									if($test['ltr_status']=='')
									{
										echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
								////////// ltr status ///////////	
									if($test['status']=='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['status']." to <br>".$r['dept_nm']."</td>";
										
									}
									else if($test['status']=='dispatched')
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									else if($test['ltr_status']=='updated')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else{
										echo "<td class='center'>".$test['status']."</td>";
									}
								//////////////////////////////////////////////////	
									echo "</tr>";
								}
								//mysql_close();
								echo"   </tbody></table>";
						
								echo "<div id='divToPrint' style='display:none;'>
								<table id='export' border='1px' style='margin-left:200px;'>
								<tr><td colspan='8'><center>".$mm['dept_nm']."रिपोर्ट्स <br> दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br>जि.रायगड<h2></center>';
								convert_marathi();	
								//GROUP BY incoming_letters_transaction.ltr_id				
								if($date123==''&& $date223=='')
								{
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=mysql_query("SELECT  t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken,i.priority_days,  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, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
									FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
									LEFT OUTER JOIN dispatched_transaction di ON di.dpt_inword_no = t.dpt_inword_no
									WHERE  t.dept_id_from='$deptid'
									AND t.returned_choice=''
									ORDER BY i.ltr_inword_no DESC") or die("sdfdfds".mysql_error());
								}
								else{
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=mysql_query("SELECT  t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken,i.priority_days, 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, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
									FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
									LEFT OUTER JOIN dispatched_transaction di ON di.dpt_inword_no = t.dpt_inword_no
									WHERE t.ltr_id=i.ltr_id 
									AND  t.dept_id_from='$deptid' 
									AND t.returned_choice=''
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
								}
								$count10=mysql_num_rows($result222);
			
								echo "
								<tr>
								<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ <br>प्राप्त_दिनांक</th>
								<th>विभाग<br>प्राप्त_दिनांक</th>
								<th>विषय</th>
								<th>कोणाकडून प्राप्त झाला</th>";
								//echo "<th>प्राधान्य दिवस </th>";
								echo "<th> केलेली <br>कार्यवाही </th>
								<th>पत्राची स्थिती </th>
								</tr>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
								/*	if($test['priority_days']=='0')
									{
										echo "<td class='center'>"."प्राधान्यता लावलेली नाही "."</td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									/////////////////////////////
									if($test['ltr_status']=='')
									{
										echo "<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
								////////// ltr status ///////////	
									if($test['status']=='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['status']." to <br>".$r['dept_nm']."</td>";
										
									}
									else if($test['status']=='dispatched')
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									else if($test['ltr_status']=='updated')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else{
										echo "<td class='center'>".$test['status']."</td>";
									}
								//////////////////////////////////////////////////	
									echo "</tr>";
								}
							} //else if($flag=='n')
								//mysql_close();
								echo "</table></div>";
			}
			######################################### End Of Display Details ###################################
				
			######################################### Display Details Deskwise ###################################
			else if( $deptid != "" && $no==2 && $deskid!="")
			{	
				convert_marathi();
				$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction,incoming_letters_transaction WHERE 	incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND tapal_to_dpt_transaction.dept_id_from='$deptid' order by incoming_letters_transaction.ltr_inword_no DESC") or die("sdfdfds".mysql_error());		
				$count10=mysql_num_rows($result222);
				echo "<table id='dyntable' class='table table-bordered border'>	
						<thead> 
						<tr>
                        <th class='head0 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
						<th class='head1 center'>संदर्भ <br>प्राप्त_दिनांक</th>
						<th class='head1 center'>विभाग<br>प्राप्त_दिनांक</th>
                        <th class='head0 center'>विषय</th>
						<th class='head1 center'>कोणाकडून प्राप्त झाला</th>";
						//echo "<th class='head0 center'>प्राधान्य दिवस </th>";
						echo "<th class='head1 center'>डेस्कला पाठवले </th>
						<th class='head0 center'>डेस्कला पाठवलेली_दिनांक </th>
						</tr>
					</thead>";
				while($test = mysql_fetch_array($result222))
					{
						$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
						$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
						if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
						{
							$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
							//echo $dis_date;
						}
						else if($test['sent_to_desk_dt']!='')
						{
							$dis_date="--" ;			
						}
						$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
						$id1 = $test['ltr_inward_no'];
						$id2 = $test['assign_dept'];
						$id3 = $test['sandarbh_prakar'];
						$deskid=$test['desk_id'];
						echo "<tr class=gradeX>
						<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
						<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
						<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
						<td class='center'>".$test['subject']."</td>
						<td class='center'>".$test['sender_name']."</td>";
					/*	if($test['priority_days']=='0')
						{
							echo "<td class='center'>"."--"."</td>";
						}
						else if($test['priority_days']>'0')
						{
							echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
						} */
						$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
						$rs09=mysql_query($qry09) or die("assssss".mysql_error());
						$rw09=mysql_fetch_array($rs09);
						$desknm=$rw09['desk_nm'];
						if($desknm!='')
						{
							echo "<td class='center'><a href=report_dpt_deskwise.php?no=2&deskid=$deskid&deptid=$deptid>".$desknm."</a></td>";
						}
						else if($desknm=='')
						{
							echo "<td class='center'>--</td>";
						}
						echo "<td class='center'>".$dis_date."</font></td>
						</tr>";
					}
					//mysql_close();
					echo"   </tbody>
					</table>";
		 
				echo "<div id='divToPrint' style='display:none;'>";
				convert_marathi();
				$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction,incoming_letters_transaction WHERE incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND tapal_to_dpt_transaction.dept_id_from='$deptid' order by incoming_letters_transaction.ltr_inword_no DESC") or die("sdfdfds".mysql_error());
				$count10=mysql_num_rows($result222);
				echo "<table id='export' style='text-align:center;'>	
						<tr>
                        <th>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
						<th>संदर्भ <br>प्राप्त_दिनांक</th>
						<th>विभाग<br>प्राप्त_दिनांक</th>
                        <th>विषय</th>
						<th>कोणाकडून प्राप्त झाला</th>";
						//echo "<th>प्राधान्य दिवस </th>";
						echo "<th>डेस्कला पाठवले </th>
						<th>डेस्कला पाठवलेली_दिनांक </th>
						</tr>
					</thead>";
				while($test = mysql_fetch_array($result222))
					{
						$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
						$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
						if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
						{
							$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
							//echo $dis_date;
						}
						else if($test['sent_to_desk_dt']!='')
						{
							$dis_date="--" ;			
						}
						$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
						$id1 = $test['ltr_inward_no'];
						$id2 = $test['assign_dept'];
						$id3 = $test['sandarbh_prakar'];
						$deskid=$test['desk_id'];
						echo "<tr>
						<td>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
						<td>".$test['ref_no']."</font><br>".$ref_date."</td>
						<td>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
						<td>".$test['subject']."</td>
						<td>".$test['sender_name']."</td>";
					/*	if($test['priority_days']=='0')
						{
							echo "<td>"."--"."</td>";
						}
						else if($test['priority_days']>'0')
						{
							echo "<td>".$test['priority_days']."</td>";		
						} */
						$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
						$rs09=mysql_query($qry09) or die("assssss".mysql_error());
						$rw09=mysql_fetch_array($rs09);
						$desknm=$rw09['desk_nm'];
						if($desknm!='')
						{
							echo "<td>".$desknm."</td>";
						}
						else if($desknm=='')
						{
							echo "<td>--</td>";
						}
						echo "<td>".$dis_date."</td>
						</tr>";
					}
					//mysql_close();
					echo "</table></div>";
			}
			################################################ End Of Display Details #################################
?><br>
					<p>	
						<center><input type="submit" 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>	
				</form>  
                <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php }
#################################################### End Of Tapal User #####################################################
#################################################### FOR BDO USER #####################################################
else if($no==3)
{
	include('dashboard_bdo.php');
	?>
	<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<script type="text/javascript">     
	function PrintDiv() {    
	var divToPrint = document.getElementById('divToPrint');
	var popupWin = window.open('', '_blank', 'width=600,height=600');
	popupWin.document.open();
	popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
	popupWin.document.close();
	}
	</script>
	<script src="tableToExcel.js"></script>
	</head>
	<body>
	<div class="mainwrapper">   
		<div class="rightpanel">
            <ul class="breadcrumbs">
				<li><a href=""><i class="iconfa-home"></i></a> <span class="separator"></span></li>
				<li><a href="">विभागानुसार रिपोर्ट्स </a> <span class="separator"></span></li>
				<li></li>
			</ul>
			<div class="pageheader">
				<div class="pageicon"><span class="iconfa-table"></span></div>
					<div class="pagetitle">
					<h1>विभागानुसार रिपोर्ट्स </h1>
					
				</div>
			</div><!--pageheader-->
			<?php 		
			######################################### Display Counter ######################################
			if($deptid=="" && $no==3)	
				{  ?>
					<div class="maincontent">
						<div class="maincontentinner">
							<h4 class="widgettitle">विभागानुसार रिपोर्ट्स </h4>
							<form method="post" action="">
								<?php
								convert_marathi();
								echo "<form name='dept_sandarbh' 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='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 method='post' action='' >";
							$date123	= $_POST['start_date'];
							$date1	= date('Y-m-d',strtotime($date123));
							$date223	= $_POST['end_date'];
							$date2	= date('Y-m-d',strtotime($date223));
							//$date22	= date('d-m-Y',strtotime($date2));
							
							if($date123==''&& $date223=='')
							{
							
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id = $date1;
								$id1= $date2;
								$qre=("SELECT t.dept_id_from,dm.desk_flag, dm.dept_nm, COUNT(*) AS TOTAL 
								FROM tapal_to_dpt_transaction t,department_master dm
								where t.dept_id_from=dm.dept_id 
								AND t.returned_choice='' and t.dpt_ltr_rec_dt BETWEEN '$date1' and '$date2' 
								GROUP BY dept_nm");
								$rsut=mysql_query($qre) or die("sssssss".mysql_error());
								
							}
							else{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id = $date1;
								$id1= $date2;
								$qre=("SELECT t.dept_id_from, dm.desk_flag, dm.dept_nm, COUNT(*) AS TOTAL 
								FROM tapal_to_dpt_transaction t,department_master dm 
								where t.dept_id_from=dm.dept_id 
								AND t.returned_choice='' and t.dpt_ltr_rec_dt BETWEEN '$date1' and '$date2' 
								GROUP BY dept_nm");
								$rsut=mysql_query($qre) or die("sssssss".mysql_error());
							}
								echo "<table id='dyntable' class='table table-bordered border'>
								<thead>
								<tr>
								<th class='head0 center' style='width:160px;'>विभागाचे नाव </th>
								<th class='head1 center'>एकूण </th>
								</tr>
								</thead>";
								while($rws = mysql_fetch_array($rsut))
								{
									$deptid=$rws['dept_id_from'];
									$deskflag=$rws['desk_flag'];
									
									if($deskflag=='Y' || $deskflag=='y' )
									{
									?>
										<tbody>
										<tr class="gradeX">
										<?php 
										echo "<td><a href='report_dptwise.php?deptid=$deptid&no=3'>".$rws['dept_nm']."</a></td><td>". $rws['TOTAL']."</td> </tr>";    
									}
									else if($deskflag=='N' || $deskflag=='n' )
									{
									?>
										<tbody>
										<tr class="gradeX">
										<?php 
										echo "<td><a href='report_dptwise.php?flag=n&deptid=$deptid&no=3'>".$rws['dept_nm']."</a></td><td>". $rws['TOTAL']."</td> </tr>";    
									}
								}?>
								</tbody>
							</table>
				
								
								<?php
								
								echo "<div id='divToPrint' style='display:none;'>
								<table id='export' border='1px' style='margin-left:550px;'>";
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br>जि.रायगड<h2></center>';
								convert_marathi();
							if($date123==''&& $date223=='')
							{
							
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id = $date1;
								$id1= $date2;
								$qre=("SELECT t.dept_id_from,dm.desk_flag, dm.dept_nm, COUNT(*) AS TOTAL 
								FROM tapal_to_dpt_transaction t,department_master dm
								where t.dept_id_from=dm.dept_id 
								AND t.returned_choice=''
								GROUP BY dept_nm");
								$rsut=mysql_query($qre) or die("sssssss".mysql_error());
								
							}
							else{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id = $date1;
								$id1= $date2;
								$qre=("SELECT t.dept_id_from, dm.desk_flag, dm.dept_nm, COUNT(*) AS TOTAL 
								FROM tapal_to_dpt_transaction t,department_master dm 
								where t.dept_id_from=dm.dept_id 
								AND t.returned_choice=''
								GROUP BY dept_nm");
								$rsut=mysql_query($qre) or die("sssssss".mysql_error());
							}
								
							//	echo "<table id='export' style='text-align:center;' >
								echo "<tr>
								<th>विभागाचे नाव </th>
								<th>एकूण </th>
								</tr>";
								while($rws = mysql_fetch_array($rsut))
								{
									$deptid=$rws['dept_id_from'];
									echo "<tr>";
									echo "<td>".$rws['dept_nm']."</td><td>". $rws['TOTAL']."</td> </tr>";                
								}
							echo "</table></div>";
			} 
				####################################### End Of Display Counter #########################################
				
				######################################### Display Details #########################################
			else if( $deptid != "" && $no==3)
			{	
				convert_marathi();
				$m=mysql_query("Select dept_nm from department_master where dept_id='$deptid'");
				$mm=mysql_fetch_array($m);	
				
				?>
				<div class="maincontent">
					<div class="maincontentinner" >
						<h4 class="widgettitle"><?php echo $mm['dept_nm'];?> रिपोर्ट्स</h4>		   
							<form method="post" action="">
								<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
								<table>
									<tr>
										<td align="center"><label style="width:110px;">Start date</label></td>
										<td align="center"><input type="text" name="start_date" class="input-small"/></td>
										<td align="center"><label style="width:110px;">End Date</label></td>
										<td align="center"><input type="text" name="end_date" class="input-small"/></td>
									</tr>
									<tr>
										<td colspan="6">
										<div align="center">
											<input type="submit" onClick="return sadyasthitiDates()" name="ok" value="GO"/>
											<input type="reset" value="CLEAR" name="clear"/>
										</div>
										</td>
									</tr>
								</table>
								</div>
							</form>
							<form action="" method="post">
								<?php
								convert_marathi();	
								$date123	= $_POST['start_date'];
								$date1	= date('Y-m-d',strtotime($date123));
								$date223	= $_POST['end_date'];
								$date2	= date('Y-m-d',strtotime($date223));
								//$date22	= date('d-m-Y',strtotime($date2));
								
						if($flag=='')
						{
								if($date123==''&& $date223=='')
								{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									/*$result222=mysql_query("SELECT de.desk_ltr_id, 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.desk_approval, t.status,t.dpt_inword_no, t.sent_to_desk_dt ,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.priority_days,  i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, di.dispatched_to,di.dept_id_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.dept_id_from='$deptid'
									ORDER BY i.ltr_inword_no DESC") or die("sdfdfds".mysql_error()); */
									
									//accpeted by dept but deskid=0 or desk_apprval=pending
									$result222=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.desk_approval,t.status, 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 (t.desk_id='0' OR t.desk_approval='pending')
									AND t.returned_choice='' 
									ORDER BY i.ltr_inword_no DESC") OR die("aabbhhaa".mysql_error());
									
									//accpeted by desk and ltrstatus!=closed
									$result2221=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.desk_approval,t.status, 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.dept_id_to, 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'
									ORDER BY i.ltr_inword_no DESC") OR die("aabbhhaa".mysql_error());
									
								}
								else{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=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.desk_approval,t.status, 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, 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,di.dept_id_to, 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.desk_id='0' OR t.desk_approval='pending') AND t.returned_choice=''
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
									
									$result2221=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.desk_approval,t.status, 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.dept_id_to, 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());
								}
								$count10=mysql_num_rows($result222);
			
								echo "<table id='dyntable' class='table table-bordered'>
								<thead> 
								<tr>
								<th class='head0 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class='head1 center'>संदर्भ <br>प्राप्त_दिनांक</th>
								<th class='head1 center'>विभाग<br>प्राप्त_दिनांक</th>
								<th class='head0 center'>विषय</th>
								<th class='head1 center'>कोणाकडून प्राप्त झाला</th>";
								//echo "<th class='head0 center'>प्राधान्य दिवस </th>";
								echo "<th class='head1 center'>डेस्कला पाठवले <br>डेस्कला पाठवलेली_दिनांक</th>
								<th class='head1 center'> केलेली <br>कार्यवाही </th>
								<th class='head0 center'>पत्राची स्थिती </th>
								</tr>
								</thead>";
								while($test = mysql_fetch_array($result222))
								{ 
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$desk=$test['desk_id'];
									
									//closed lettr
									$ltrinward=$test['ltr_inword_no'];
									$deskidfrom=$test['desk_id_from'];
									
									if($test['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'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									convert_marathi();
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//echo $desknm."bbbbbbb";
									
									$qry091="Select desk_nm from desk_master where desk_id='$desk'";
									$rs091=mysql_query($qry091) or die("aass".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									$desknm1=$rw091['desk_nm'];
									//echo $desknm1['desk_nm'];
									///////////////////////////////////////////////////////////
									 if($test['desk_approval']=='pending')
									{
										
										echo "<td class='center'><font color='red'>".$desknm1."<br>डेस्कने स्वीकारणे बाकी </font></td> ";
									}
									else if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'>डेस्कला पाठवलेले नाही</font> </td> ";
									}
									else if($desknm!='')
									{
										echo "<td class='center'><a href='report_dpt_deskwise.php?no=3&deskid=$deskid&deptid=$deptid'>".$desknm."</a>";
									}
									
									echo "<br>".$dis_date."</font></td>";
									/////////////////// Action Taken //////////////////////////////
							
								/*	if($result['rtn_to_dsk']=='')
									{
										$returnto=$mm['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($test['ltr_status']=='')
									{
										echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी </font></td> ";
									}
									else if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									} */
									echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी </font></td> ";
									/////////////////////////////////////////////////////////////////
									$depti=$test['dept_id_to'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									
									if($test['ltr_approval']=='transferred')
									{
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$dept['dept_nm']."</td>";
									}
									else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='updated' )
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if( $test['ltr_status']=='closed')
									{
										echo "<td class='center'>".$test['desk_approval']."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									echo "</tr>";
								}
								//mysql_close();
								while($test = mysql_fetch_array($result2221))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$desk=$test['desk_id'];
									
									//closed lettr
									$ltrinward=$test['ltr_inword_no'];
									$deskidfrom=$test['desk_id_from'];
									
									if($test['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'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									convert_marathi();
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//echo $desknm."bbbbbbb";
									
									$qry091="Select desk_nm from desk_master where desk_id='$desk'";
									$rs091=mysql_query($qry091) or die("aass".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									$desknm1=$rw091['desk_nm'];
									//echo $desknm1['desk_nm'];
									///////////////////////////////////////////////////////////
									if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'><a href='report_dpt_deskwise.php?no=3&deskid=$deskid&deptid=$deptid'>".$desknm."</a><br>".$dis_date."</td>";
									}
									else if($test['desk_approval']=='pending')
									{
										
										echo "<td class='center'><font color='red'>".$desknm1."<br>डेस्कने स्वीकारणे बाकी </font></td> ";
									}
									else if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'>डेस्कला पाठवलेले नाही</font> </td> ";
									}
									else if($desknm!='')
									{
										echo "<td class='center'><a href='report_dpt_deskwise.php?no=3&deskid=$deskid&deptid=$deptid'>".$desknm."</a>";
									}
									
									echo "<br>".$dis_date."</font></td>";
									/////////////////// Action Taken //////////////////////////////
							
									if($result['rtn_to_dsk']=='')
									{
										$returnto=$mm['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($test['ltr_status']=='')
									{
										echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी </font></td> ";
									}
									else if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									/////////////////////////////////////////////////////////////////
									$depti=$test['dept_id_to'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									
									if($test['ltr_approval']=='transferred')
									{
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$dept['dept_nm']."</td>";
									}
									else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='updated' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['status']."</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='8'><center> ".$mm['dept_nm']."रिपोर्ट्स <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br>जि.रायगड<h2></center>';
								convert_marathi();	
								//GROUP BY incoming_letters_transaction.ltr_id				
								if($date123==''&& $date223=='')
								{
									$id1 = $date1;
									$id2= $date2;
									
									//accpeted by dept but deskid=0 or desk_apprval=pending
									$result222=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.desk_approval,t.status, 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 (t.desk_id='0' OR t.desk_approval='pending')
									AND t.returned_choice=''
									ORDER BY i.ltr_inword_no DESC") OR die("aabbhhaa".mysql_error());
									 
									//accpeted by desk and ltrstatus!=closed
									$result2221=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.desk_approval,t.status, 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.dept_id_to, 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'
									ORDER BY i.ltr_inword_no DESC") OR die("aabbhhaa".mysql_error());
								}
								else{
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=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.desk_approval,t.status, 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, i.ref_dt, i.ref_no, i.dept_id, i.document,di.dept_id_to, 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.desk_id='0' OR t.desk_approval='pending') AND t.returned_choice=''
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
									
									$result2221=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.desk_approval,t.status, 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,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());
								}
								$count10=mysql_num_rows($result222);
			
								echo "
								<tr>
								<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ <br>प्राप्त_दिनांक</th>
								<th>विभाग<br>प्राप्त_दिनांक</th>
								<th>विषय</th>
								<th>कोणाकडून प्राप्त झाला</th>";
								//echo "<th>प्राधान्य दिवस </th>";
								echo "<th>डेस्कला पाठवले <br>डेस्कला पाठवलेली_दिनांक</th>
								<th> केलेली <br>कार्यवाही </th>
								<th>पत्राची स्थिती </th>
								</tr>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$desk=$test['desk_id'];
									
									//closed lettr
									$ltrinward=$test['ltr_inword_no'];
									$deskidfrom=$test['desk_id_from'];
									
									if($test['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'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									convert_marathi();
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//echo $desknm."bbbbbbb";
									
									$qry091="Select desk_nm from desk_master where desk_id='$desk'";
									$rs091=mysql_query($qry091) or die("aass".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									$desknm1=$rw091['desk_nm'];
									//echo $desknm1['desk_nm'];
									///////////////////////////////////////////////////////////
									 if($test['desk_approval']=='pending')
									{
										
										echo "<td class='center'>".$desknm1."<br>डेस्कने स्वीकारणे बाकी </td> ";
									}
									else if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'>डेस्कला पाठवलेले नाही </td> ";
									}
									else if($desknm!='')
									{
										echo "<td class='center'>".$desknm."";
									}
									
									echo "<br>".$dis_date."</font></td>";
									/////////////////// Action Taken //////////////////////////////
							/*
									if($result['rtn_to_dsk']=='')
									{
										$returnto=$mm['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($test['ltr_status']=='')
									{
										echo "<td class='center'>कार्यवाही करणे बाकी </td> ";
									}
									else if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}*/
									
									echo "<td class='center'>कार्यवाही करणे बाकी </td> ";
									/////////////////////////////////////////////////////////////////
									$depti=$test['dept_id_to'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									
									if($test['ltr_approval']=='transferred')
									{
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$dept['dept_nm']."</td>";
									}
									else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='updated' )
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if( $test['ltr_status']=='closed')
									{
										echo "<td class='center'>".$test['desk_approval']."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									echo "</tr>";
								}
								//mysql_close();
								while($test = mysql_fetch_array($result2221))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$desk=$test['desk_id'];
									
									//closed lettr
									$ltrinward=$test['ltr_inword_no'];
									$deskidfrom=$test['desk_id_from'];
									
									if($test['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'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									convert_marathi();
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//echo $desknm."bbbbbbb";
									
									$qry091="Select desk_nm from desk_master where desk_id='$desk'";
									$rs091=mysql_query($qry091) or die("aass".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									$desknm1=$rw091['desk_nm'];
									//echo $desknm1['desk_nm'];
									///////////////////////////////////////////////////////////
									if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>".$desknm."<br>".$dis_date."</td>";
									}
									else if($test['desk_approval']=='pending')
									{
										
										echo "<td class='center'>".$desknm1."<br>डेस्कने स्वीकारणे बाकी </td> ";
									}
									else if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'>डेस्कला पाठवलेले नाही </td> ";
									}
									else if($desknm!='')
									{
										echo "<td class='center'>".$desknm."";
									}
									
									echo "<br>".$dis_date."</font></td>";
									/////////////////// Action Taken //////////////////////////////
							
									if($result['rtn_to_dsk']=='')
									{
										$returnto=$mm['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($test['ltr_status']=='')
									{
										echo "<td class='center'>कार्यवाही करणे बाकी </td> ";
									}
									else if($test['ltr_status']=='closed' )
									{
										echo"<td class='center'>Letter Returned To <br>".$returnto."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									/////////////////////////////////////////////////////////////////
									$depti=$test['dept_id_to'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									
									if($test['ltr_approval']=='transferred')
									{
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$dept['dept_nm']."</td>";
									}
									else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='updated' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									
									else
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									echo "</tr>";
								}
							}
							
						else if($flag=='n')
						{
								if($date123==''&& $date223=='')
								{
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=mysql_query("SELECT  t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken,i.priority_days,  i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to,di.dept_id_to, t.ltr_category, t.assign_no 
									FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
									LEFT OUTER JOIN dispatched_transaction di ON di.dpt_inword_no = t.dpt_inword_no
									WHERE  t.dept_id_from='$deptid'
									AND t.returned_choice=''
									ORDER BY i.ltr_inword_no DESC") or die("sdfdfds".mysql_error());
								}
								else{
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=mysql_query("SELECT  t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken,i.priority_days, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc,di.dept_id_to, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
									FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
									LEFT OUTER JOIN dispatched_transaction di ON di.dpt_inword_no = t.dpt_inword_no
									WHERE t.ltr_id=i.ltr_id 
									AND  t.dept_id_from='$deptid' 
									AND t.returned_choice=''
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
								}
								$count10=mysql_num_rows($result222);
			
								echo "<table id='dyntable' class='table table-bordered'>
								<thead> 
								<tr>
								<th class='head0 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class='head1 center'>संदर्भ <br>प्राप्त_दिनांक</th>
								<th class='head1 center'>विभाग<br>प्राप्त_दिनांक</th>
								<th class='head0 center'>विषय</th>
								<th class='head1 center'>कोणाकडून प्राप्त झाला </th>";
								//echo "<th class='head0 center'>प्राधान्य दिवस </th>";
								echo "<th class='head0 center'> केलेली <br>कार्यवाही </th>
								<th class='head0 center'>पत्राची स्थिती </th>
								</tr>
								</thead>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
									/*if($test['priority_days']=='0')
									{
										echo "<td class='center'><font color='red'>"."प्राधान्यता लावलेली नाही "."</font></td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									/////////////////////////////
									if($test['ltr_status']=='')
									{
										echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
								////////// ltr status ///////////	
									if($test['status']=='transferred')
									{
										$transfrto=$test['dept_id_to'];
										$qry=mysql_query("Select dept_nm from department_master where dept_id='$transfrto' ");
										$rs=mysql_fetch_array($qry);
										
										echo "<td class='center'>".$test['status']." to <br>".$rs['dept_nm']."</td>";
									}
									else if($test['status']=='dispatched')
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									else if($test['ltr_status']=='updated')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else{
										echo "<td class='center'>".$test['status']."</td>";
									}
								//////////////////////////////////////////////////	
									echo "</tr>";
								}
								//mysql_close();
								echo"   </tbody></table>";
						
								echo "<div id='divToPrint' style='display:none;'>
								<center><table id='export' border='1px' style='margin-left:50px;'>
								<tr><td colspan='8'><center>".$mm['dept_nm']."रिपोर्ट्स <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								echo ' <center><h2>पोलीस अधिक्षक <br> कार्यालय <br>जि.रायगड<h2></center>';
								convert_marathi();	
								//GROUP BY incoming_letters_transaction.ltr_id				
								if($date123==''&& $date223=='')
								{
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=mysql_query("SELECT  t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken,i.priority_days,  i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc,di.dept_id_to, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
									FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
									LEFT OUTER JOIN dispatched_transaction di ON di.dpt_inword_no = t.dpt_inword_no
									WHERE  t.dept_id_from='$deptid'
									AND t.returned_choice=''
									ORDER BY i.ltr_inword_no DESC") or die("sdfdfds".mysql_error());
								}
								else{
									$id1 = $date1;
									$id2= $date2;
									//GROUP BY incoming_letters_transaction.ltr_id				
									$result222=mysql_query("SELECT  t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken,i.priority_days, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc,di.dept_id_to, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
									FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
									LEFT OUTER JOIN dispatched_transaction di ON di.dpt_inword_no = t.dpt_inword_no
									WHERE t.ltr_id=i.ltr_id 
									AND  t.dept_id_from='$deptid' 
									AND t.returned_choice=''
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
								}
								$count10=mysql_num_rows($result222);
			
								echo "
								<tr>
								<th>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ <br>प्राप्त_दिनांक</th>
								<th>विभाग<br>प्राप्त_दिनांक</th>
								<th>विषय</th>
								<th>कोणाकडून प्राप्त झाला</th>";
								//echo "<th>प्राधान्य दिवस </th>";
								echo "<th> केलेली <br>कार्यवाही </th>
								<th>पत्राची स्थिती </th>
								</tr>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
									
								/*	if($test['priority_days']=='0')
									{
										echo "<td class='center'>"."प्राधान्यता लावलेली नाही "."</td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
									} */
									/////////////////////////////
									if($test['ltr_status']=='')
									{
										echo "<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
								////////// ltr status ///////////	
									if($test['status']=='transferred')
									{
										$transfrto=$test['dept_id_to'];
										$qry=mysql_query("Select dept_nm from department_master where dept_id='$transfrto' ");
										$rs=mysql_fetch_array($qry);
										
										echo "<td class='center'>".$test['status']." to <br>".$rs['dept_nm']."</td>";
									}
									else if($test['status']=='dispatched')
									{
										echo "<td class='center'>".$test['status']."</td>";
									}
									else if($test['ltr_status']=='updated')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else{
										echo "<td class='center'>".$test['status']."</td>";
									}
								//////////////////////////////////////////////////	
									echo "</tr>";
								}
							} //else if($flag=='n')
								//mysql_close();
								echo "</table></center></div>";
			}
			######################################### End Of Display Details ###################################
				
			######################################### Display Details Deskwise ###################################
			else if( $deptid != "" && $no==3 && $deskid!="")
			{	
				convert_marathi();
				$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction,incoming_letters_transaction WHERE 	incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND tapal_to_dpt_transaction.dept_id_from='$deptid' order by incoming_letters_transaction.ltr_inword_no DESC") or die("sdfdfds".mysql_error());		
				$count10=mysql_num_rows($result222);
				echo "<table id='dyntable' class='table table-bordered border'>	
						<thead> 
						<tr>
                        <th class='head0 center'>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
						<th class='head1 center'>संदर्भ <br>प्राप्त_दिनांक</th>
						<th class='head1 center'>विभाग<br>प्राप्त_दिनांक</th>
                        <th class='head0 center'>विषय</th>
						<th class='head1 center'>कोणाकडून प्राप्त झाला</th>";
						//echo "<th class='head0 center'>प्राधान्य दिवस </th>";
						echo "<th class='head1 center'>डेस्कला पाठवले </th>
						<th class='head0 center'>डेस्कला पाठवलेली_दिनांक </th>
						</tr>
					</thead>";
				while($test = mysql_fetch_array($result222))
					{
						$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
						$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
						if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
						{
							$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
							//echo $dis_date;
						}
						else if($test['sent_to_desk_dt']!='')
						{
							$dis_date="--" ;			
						}
						$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
						$id1 = $test['ltr_inward_no'];
						$id2 = $test['assign_dept'];
						$id3 = $test['sandarbh_prakar'];
						$deskid=$test['desk_id'];
						echo "<tr class=gradeX>
						<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
						<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
						<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
						<td class='center'>".$test['subject']."</td>
						<td class='center'>".$test['sender_name']."</td>";
					/*	if($test['priority_days']=='0')
						{
							echo "<td class='center'>"."--"."</td>";
						}
						else if($test['priority_days']>'0')
						{
							echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=3'>".$test['priority_days']."</a></td>";		
						} */
						$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
						$rs09=mysql_query($qry09) or die("assssss".mysql_error());
						$rw09=mysql_fetch_array($rs09);
						$desknm=$rw09['desk_nm'];
						if($desknm!='')
						{
							echo "<td class='center'><a href=report_dpt_deskwise.php?no=3&deskid=$deskid&deptid=$deptid>".$desknm."</a></td>";
						}
						else if($desknm=='')
						{
							echo "<td class='center'>--</td>";
						}
						echo "<td class='center'>".$dis_date."</font></td>
						</tr>";
					}
					//mysql_close();
					echo"   </tbody>
					</table>";
		 
				echo "<div id='divToPrint' style='display:none;'>";
				convert_marathi();
				$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction,incoming_letters_transaction WHERE incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND tapal_to_dpt_transaction.dept_id_from='$deptid' order by incoming_letters_transaction.ltr_inword_no DESC") or die("sdfdfds".mysql_error());
				$count10=mysql_num_rows($result222);
				echo "<table id='export' style='text-align:center;'>	
						<tr>
                        <th>पोलीस अधिक्षक <br> कार्यालय <br> आवक_क्रमांक<br>आवक_दिनांक</th>
						<th>संदर्भ <br>प्राप्त_दिनांक</th>
						<th>विभाग<br>प्राप्त_दिनांक</th>
                        <th>विषय</th>
						<th>कोणाकडून प्राप्त झाला</th>";
						//echo "<th>प्राधान्य दिवस </th>";
						echo "<th>डेस्कला पाठवले </th>
						<th>डेस्कला पाठवलेली_दिनांक </th>
						</tr>
					</thead>";
				while($test = mysql_fetch_array($result222))
					{
						$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
						$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
						if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
						{
							$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
							//echo $dis_date;
						}
						else if($test['sent_to_desk_dt']!='')
						{
							$dis_date="--" ;			
						}
						$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
						$id1 = $test['ltr_inward_no'];
						$id2 = $test['assign_dept'];
						$id3 = $test['sandarbh_prakar'];
						$deskid=$test['desk_id'];
						echo "<tr>
						<td>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
						<td>".$test['ref_no']."</font><br>".$ref_date."</td>
						<td>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
						<td>".$test['subject']."</td>
						<td>".$test['sender_name']."</td>";
					/*	if($test['priority_days']=='0')
						{
							echo "<td>"."--"."</td>";
						}
						else if($test['priority_days']>'0')
						{
							echo "<td>".$test['priority_days']."</td>";		
						} */
						$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
						$rs09=mysql_query($qry09) or die("assssss".mysql_error());
						$rw09=mysql_fetch_array($rs09);
						$desknm=$rw09['desk_nm'];
						if($desknm!='')
						{
							echo "<td>".$desknm."</td>";
						}
						else if($desknm=='')
						{
							echo "<td>--</td>";
						}
						echo "<td>".$dis_date."</td>
						</tr>";
					}
					//mysql_close();
					echo "</table></div>";
			}
} ######################################### Display Details Deskwise ###################################
?>				<br>
				<p>	
					<center><input type="submit" 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>	
			</form>
                <br /><br />
                 <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->      
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>


