<!DOCTYPE html>
<?php
$flag=$_REQUEST['flag'];
if($flag=='')
{
require_once('convert_marathi.php');
$no=$_GET['no'];
$ltrid=$_REQUEST['ltr_id'];
##################################### Sandharbh Wise Report For Tapal User ###########################################
if($no==2)
{
		$username = $_SESSION['User_Name'];
		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="">Tables</a> <span class="separator"></span></li>
            <li>संदर्भ प्रकारानुसार  रिपोर्ट्स</li>
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
			<div class="pagetitle">
				<h5>Tables</h5>
				<?php 
				$qryz=mysql_query("Select dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
				$rsz=mysql_fetch_array($qryz);
				
				
				$qry=mysql_query("Select sandharbh_nm from sandharbh_master where sandhrbh_id='$ltrid' ");
				$rs=mysql_fetch_array($qry);
				// echo $rs['sandharbh_nm'];
				?>
				<h1><?php echo 	$rsz['dept_nm'];?>संदर्भ प्रकारानुसार  रिपोर्ट्स</h1>
			</div>
		</div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
			    <h4 class="widgettitle"><?php echo 	$rsz['dept_nm'];?>संदर्भ प्रकारानुसार  रिपोर्ट्स ( <?php echo $rs['sandharbh_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 		
				if($ltrid=="" && $no==2)
				{
					    convert_marathi();
						echo "<table id='dyntable' class='table table-bordered'>		
								<thead>
								<tr>
								<th class='head0 center' style='width:160px;'>संदर्भाचे नाव </th>
								<th class='head1 center'>एकूण </th>
								</tr>
								</thead>";
						
					$query=("SELECT * FROM sandharbh_master");
					$rsut0=mysql_query($query) or die("".mysql_error());
					
						$c=0;
					while($row = mysql_fetch_array($rsut0))
					{
						$sid=$row['sandhrbh_id'];
						
						/*/////////////dept accepted ltr///////
						$qre=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
						where t.ltr_id=i.ltr_id
						AND i.ltr_type='$sid'
						AND i.status='approve' ");
						$rsut=mysql_query($qre) or die("".mysql_error());
						
						//////////dept not accepted ltr/////////////
						$qree=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i
						where i.status='pending'
						AND i.ltr_type='$sid' ");
						$rsut1=mysql_query($qree) or die("".mysql_error());*/
						
						///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
						$result222=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
						WHERE t.ltr_id=i.ltr_id
						AND i.ltr_type='$sid'
						AND t.returned_choice=''
						AND (t.desk_id='0' OR t.desk_approval='pending')
						AND t.status!='transferred' ") or die("sdfdfds".mysql_error());
						$rsut=mysql_query($result222) or die("ccc".mysql_error());
													
						/////// not assigned dept or not accepted by dept//////////
						$result2223=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i
						where (i.status='pending' || i.dept_id='0')
						AND i.ltr_type='$sid'") or die("sdfdfds".mysql_error());
						$rsut1=mysql_query($result2223) or die("bbb".mysql_error());
													
						///////desk accpted ltrs ecept transferred ane returnd///////
						$result22231=("SELECT COUNT(*) AS TOTAL 
						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 i.ltr_type='$sid'
						AND de.ltr_status!='closed'
						AND de.ltr_approval!='transferred'
						AND de.ltr_approval!='transferred_todesk' ") or die("sdfdfds".mysql_error());
						$rsut2=mysql_query($result22231) or die("aaa".mysql_error());	
						
						
						$i=0;
						$j=0;
						$k=0;
						
						while($rws = mysql_fetch_array($rsut))
						{
							$arr[$i]=$rws['TOTAL'];
							//echo $arr[$i];
						
						}
						while($rws1 = mysql_fetch_array($rsut1))
						{
							$arr1[$j]=$rws1['TOTAL'];
							//echo $arr1[$j];
							
						}
						while($rws2 = mysql_fetch_array($rsut2))
						{
							$arr2[$k]=$rws2['TOTAL'];
							//echo $arr1[$j];
							
						}
						$arr3[$c]=$arr[$i]+$arr1[$j]+$arr2[$k];
						echo "<td class='center'><a href='report_dpt_sandharbha.php?ltr_id=$sid&no=2'>".$row['sandharbh_nm']."</a></td><td>". $arr3[$c]."</td> </tr>";
							$i++;
							$j++; 
							$k++;
							$c++;
					}
					?>
					</tbody>
					</table>
							<?php
							echo "<div id='divToPrint' style='display:none;'>
							<center><table id='export' border='1px' style='margin-left:550px;'>
							<tr><td colspan='8'><center><h4>".	$rsz['dept_nm']."संदर्भ प्रकारानुसार  रिपोर्ट्स </h4></center></td></tr>";
							echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
								convert_marathi();
								$query=("SELECT * FROM sandharbh_master");
					$rsut0=mysql_query($query) or die("".mysql_error());
					
						$c=0;
					while($row = mysql_fetch_array($rsut0))
					{
						$sid=$row['sandhrbh_id'];
						
						///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
						$result222=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
						WHERE t.ltr_id=i.ltr_id
						AND i.ltr_type='$sid'
						AND t.returned_choice=''
						AND (t.desk_id='0' OR t.desk_approval='pending')
						AND t.status!='transferred' ") or die("sdfdfds".mysql_error());
						$rsut=mysql_query($result222) or die("ccc".mysql_error());
													
						/////// not assigned dept or not accepted by dept//////////
						$result2223=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i
						where (i.status='pending' || i.dept_id='0')
						AND i.ltr_type='$sid'") or die("sdfdfds".mysql_error());
						$rsut1=mysql_query($result2223) or die("bbb".mysql_error());
													
						///////desk accpted ltrs ecept transferred ane returnd///////
						$result22231=("SELECT COUNT(*) AS TOTAL 
						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 i.ltr_type='$sid'
						AND de.ltr_status!='closed'
						AND de.ltr_approval!='transferred' AND de.ltr_approval!='transferred_todesk' ") or die("sdfdfds".mysql_error());
						$rsut2=mysql_query($result22231) or die("aaa".mysql_error());	
						
						
						$i=0;
						$j=0;
						$k=0;
						
						while($rws = mysql_fetch_array($rsut))
						{
							$arr[$i]=$rws['TOTAL'];
							//echo $arr[$i];
						
						}
						while($rws1 = mysql_fetch_array($rsut1))
						{
							$arr1[$j]=$rws1['TOTAL'];
							//echo $arr1[$j];
							
						}
						while($rws2 = mysql_fetch_array($rsut2))
						{
							$arr2[$k]=$rws2['TOTAL'];
							//echo $arr1[$j];
							
						}
						$arr3[$c]=$arr[$i]+$arr1[$j]+$arr2[$k];
						echo "<td class='center'>".$row['sandharbh_nm']."</td><td class='center' width='80'>". $arr3[$c]."</td> </tr>";
							$i++;
							$j++; 
							$k++;
							$c++;
					}
								echo "</table></center></div>";	
							
					} 	
					else if( $ltrid != "" && $no==2)
					{
						convert_marathi();		
						$date123	= $_POST['start_date'];
						$date1	= date('Y-m-d',strtotime($date123));
						$date223	= $_POST['end_date'];
						$date2	= date('Y-m-d',strtotime($date223));
						//$date22	= date('d-m-Y',strtotime($date2));
						if($date123==''&& $date223=='')
						{
							echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
							$id1 = $date1;
							$id2= $date2;
							
							///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
							$result222=mysql_query("SELECT * FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
							WHERE t.ltr_id=i.ltr_id
							AND i.ltr_type='$ltrid'
							AND t.returned_choice=''
							AND (t.desk_id='0' OR t.desk_approval='pending')
							AND t.status!='transferred' ") or die("sdfdfds".mysql_error());
							
							/////// not assigned dept or not accepted by dept//////////
							$result2223=mysql_query("SELECT * FROM incoming_letters_transaction i
							where (i.status='pending' || i.dept_id='0')
							AND i.ltr_type='$ltrid'") or die("sdfdfds".mysql_error());
							
							///////desk accpted ltrs except transferred ane returnd///////
							$result22231=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
							WHERE i.ltr_type='$ltrid'
							AND de.ltr_status!='closed'
							AND de.ltr_approval!='transferred'
							AND de.ltr_approval!='transferred_todesk' ") 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;
							
							///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
							$result222=mysql_query("SELECT * FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
							WHERE t.ltr_id=i.ltr_id
							AND i.ltr_type='$ltrid'
							AND t.returned_choice=''
							AND (t.desk_id='0' OR t.desk_approval='pending')
							AND t.status!='transferred'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
							/////// not assigned dept or not accepted by dept//////////
							$result2223=mysql_query("SELECT * FROM incoming_letters_transaction i
							where (i.status='pending' || i.dept_id='0')
							AND i.ltr_type='$ltrid'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
							///////desk accpted ltrs ecept transferred ane returnd///////
							$result22231=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
							WHERE i.ltr_type='$ltrid'
							AND de.ltr_status!='closed'
							AND de.ltr_approval!='transferred' AND de.ltr_approval!='transferred_todesk'
							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>व_दिनांक</th>
                            <th class='head1 center'>संदर्भ <br>क्रमांक_व_दिनांक</th>
							<th class=head1 center> विभाग आवक_क्रमांक <br>व_दिनांक</th>
                            <th class='head1 center'>विषय</th>
							<th class='head0 center'>कोणाकडून प्राप्त झाला</th>";
							//echo "<th class='head1 center'>प्राधान्य दिवस </th>";
							echo "<th class='head0 center'>विभाग पाठवले </th>	";
							
							//echo  "<th class='head0 center'>विभागाला_संदर्भ पाठवलेली_दिनांक </th>";
							echo "</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']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test['ltr_inward_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$deptid=$test['dept_id_from'];
				
								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>".$dept_rec_date."</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 dept_nm from department_master where dept_id='$deptid'";
								$rs09=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw09=mysql_fetch_array($rs09))
								{
									$deptnm=$rw09['dept_nm'];
								}
								if($deptnm!='')
								{
									echo "<td class='center'><a href=report_dptwise.php?no=2&dept_id=$deptid>".$deptnm."</a></td>";
								}
								else if($deptnm=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
							
							while($test1 = mysql_fetch_array($result2223))
							{
								$ref_date 		= date('d-m-Y',strtotime($test1['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test1['receive_dt']));
								//$dept_rec_date 		= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test1['ltr_inward_no'];
								$id2 = $test1['assign_dept'];
								$id3 = $test1['sandarbh_prakar'];
								$deptid=$test1['dept_id'];
				
								echo "<tr class='gradeX'>
								<td class='center'>".$test1['ltr_inword_no']."<br>".$rec_date ."</td>
								<td class='center'>".$test1['ref_no']."</font><br>".$ref_date."</td>";
								
								if($test1['dept_id']=='0' || $test1['dept_id']=='')
								{
									echo "<td class='center'><font color='red'> विभाग लावणे बाकी  </font></td>";
								}
								else
								{
									echo "<td class='center'><font color='red'> विभागाने स्वीकारणे बाकी  </font></td>";
								}
								echo "<td class='center'>".$test1['subject']."</td>
								<td class='center'>".$test1['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 dept_nm from department_master where dept_id='$deptid'";
								$rs091=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw091=mysql_fetch_array($rs091))
								{
									$deptnm1=$rw091['dept_nm'];
								}
								if($deptnm1!='')
								{
									echo "<td class='center'><a href=report_dptwise.php?no=2&dept_id=$deptid>".$deptnm1."</a></td>";
								}
								else if($deptnm1=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
							while($test = mysql_fetch_array($result22231))
							{
								$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test['ltr_inward_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$deptid=$test['dept_id_from'];
				
								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>".$dept_rec_date."</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 dept_nm from department_master where dept_id='$deptid'";
								$rs09=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw09=mysql_fetch_array($rs09))
								{
									$deptnm=$rw09['dept_nm'];
								}
								if($deptnm!='')
								{
									echo "<td class='center'><a href=report_dptwise.php?no=2&dept_id=$deptid>".$deptnm."</a></td>";
								}
								else if($deptnm=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
						echo"   </tbody>
						</table>";
						
						echo "<div id='divToPrint' style='display:none;'>";
							echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
							echo "<center><table id='export' border='1px' style='margin-left:270px;'>
							<tr><td colspan='8'><center>संदर्भनुसार रिपोर्ट्स ( ".$rs['sandharbh_nm']." ) <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
						
						convert_marathi();			
						if($date123==''&& $date223=='')
						{
							$id1 = $date1;
							$id2= $date2;
							
							///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
							$result222=mysql_query("SELECT * FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
							WHERE t.ltr_id=i.ltr_id
							AND i.ltr_type='$ltrid'
							AND t.returned_choice=''
							AND (t.desk_id='0' OR t.desk_approval='pending')
							AND t.status!='transferred' ") or die("sdfdfds".mysql_error());
							
							/////// not assigned dept or not accepted by dept//////////
							$result2223=mysql_query("SELECT * FROM incoming_letters_transaction i
							where (i.status='pending' || i.dept_id='0')
							AND i.ltr_type='$ltrid'") or die("sdfdfds".mysql_error());
							
							///////desk accpted ltrs ecept transferred ane returnd///////
							$result22231=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
							WHERE i.ltr_type='$ltrid'
							AND de.ltr_status!='closed'
							AND de.ltr_approval!='transferred' ") or die("sdfdfds".mysql_error());
							
						}
						else{
							$id1 = $date1;
							$id2= $date2;
							
							///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
							$result222=mysql_query("SELECT * FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
							WHERE t.ltr_id=i.ltr_id
							AND i.ltr_type='$ltrid'
							AND t.returned_choice=''
							AND (t.desk_id='0' OR t.desk_approval='pending')
							AND t.status!='transferred'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
							/////// not assigned dept or not accepted by dept//////////
							$result2223=mysql_query("SELECT * FROM incoming_letters_transaction i
							where (i.status='pending' || i.dept_id='0')
							AND i.ltr_type='$ltrid'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
							///////desk accpted ltrs ecept transferred ane returnd///////
							$result22231=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
							WHERE i.ltr_type='$ltrid'
							AND de.ltr_status!='closed'
							AND de.ltr_approval!='transferred'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
						}
						$count10=mysql_num_rows($result222);
						echo "	
							<tr>
                           <th class='head0 center'>पोलीस अधिक्षक कार्यालय<br> आवक_क्रमांक <br>व_दिनांक</th>
                            <th class='head1 center'>संदर्भ <br>क्रमांक_व_दिनांक</th>
							<th class=head1 center> विभाग आवक_क्रमांक <br>व_दिनांक</th>
                            <th class='head1 center'>विषय</th>
							<th class='head0 center'>कोणाकडून प्राप्त झाला</th>";
							//echo "<th class='head1 center'>प्राधान्य दिवस </th>";
							echo "<th class='head0 center'>विभाग पाठवले </th>	";
							
							//echo  "<th class='head0 center'>विभागाला_संदर्भ पाठवलेली_दिनांक </th>";
							echo "</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']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test['ltr_inward_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$deptid=$test['dept_id_from'];
				
								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>".$dept_rec_date."</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 dept_nm from department_master where dept_id='$deptid'";
								$rs09=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw09=mysql_fetch_array($rs09))
								{
									$deptnm=$rw09['dept_nm'];
								}
								if($deptnm!='')
								{
									echo "<td class='center'>".$deptnm."</td>";
								}
								else if($deptnm=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
							
							while($test1 = mysql_fetch_array($result2223))
							{
								$ref_date 		= date('d-m-Y',strtotime($test1['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test1['receive_dt']));
								//$dept_rec_date 		= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test1['ltr_inward_no'];
								$id2 = $test1['assign_dept'];
								$id3 = $test1['sandarbh_prakar'];
								$deptid=$test1['dept_id'];
				
								echo "<tr class='gradeX'>
								<td class='center'>".$test1['ltr_inword_no']."<br>".$rec_date ."</td>
								<td class='center'>".$test1['ref_no']."</font><br>".$ref_date."</td>";
								
								if($test1['dept_id']=='0' || $test1['dept_id']=='')
								{
									echo "<td class='center'> विभाग लावणे बाकी  </td>";
								}
								else
								{
									echo "<td class='center'> विभागाने स्वीकारणे बाकी  </td>";
								}
								echo "<td class='center'>".$test1['subject']."</td>
								<td class='center'>".$test1['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 dept_nm from department_master where dept_id='$deptid'";
								$rs091=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw091=mysql_fetch_array($rs091))
								{
									$deptnm1=$rw091['dept_nm'];
								}
								if($deptnm1!='')
								{
									echo "<td class='center'>".$deptnm1."</td>";
								}
								else if($deptnm1=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
							while($test = mysql_fetch_array($result22231))
							{
								$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test['ltr_inward_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$deptid=$test['dept_id_from'];
				
								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>".$dept_rec_date."</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 dept_nm from department_master where dept_id='$deptid'";
								$rs09=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw09=mysql_fetch_array($rs09))
								{
									$deptnm=$rw09['dept_nm'];
								}
								if($deptnm!='')
								{
									echo "<td class='center'>".$deptnm."</td>";
								}
								else if($deptnm=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
						echo" </table></center></div>";
					}
					?>
					<br>
					<p>	
						<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
						<input type="button" class="btn" onclick="tableToExcel('export', 'W3C Example Table')" value="Export to Excel"></center>
					</p>
				</form>
				   </div><!--maincontentinner-->
        
                        <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php
}
############################# End of Sandharbh Wise Report For Tapal User ######################################


############################ Sandharbh Wise Report For Department User ########################################
else if($no=='1')
{
$username = $_SESSION['User_Name'];	
include('dashboard_department.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="">Tables</a> <span class="separator"></span></li>
            <li>संदर्भनुसार रिपोर्ट्स</li> 
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
                <?php 
				$qryz=mysql_query("Select dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
				$rsz=mysql_fetch_array($qryz);
				
				$qry=mysql_query("Select sandharbh_nm from sandharbh_master where sandhrbh_id='$ltrid' ");
				$rs=mysql_fetch_array($qry);
				?>
                <h1><?php echo 	$rsz['dept_nm'];?>चे संदर्भनुसार रिपोर्ट्स</h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
					<h4 class="widgettitle"> <?php echo $rsz['dept_nm'];?>चे संदर्भनुसार रिपोर्ट्स ( <?php echo $rs['sandharbh_nm'];?>) </h4>
					<form method="post" action="">
						<?php 		
						if($ltrid=="")
							{
								convert_marathi();
								/*$qre=("SELECT tapal_to_dpt_transaction.dept_id_from, incoming_letters_transaction.ltr_type, sandharbh_master.sandharbh_nm, COUNT(*) AS TOTAL FROM incoming_letters_transaction,sandharbh_master,tapal_to_dpt_transaction where 
								tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id AND
								incoming_letters_transaction.ltr_type=sandharbh_master.sandhrbh_id  AND incoming_letters_transaction.dept_id=(select dept_id from login where login_id='$username') GROUP BY sandharbh_nm"); */
								
								/*$qre=("SELECT t.dept_id_from, i.ltr_type, sm.sandharbh_nm, COUNT(*) AS TOTAL 
								FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON  t.ltr_id=i.ltr_id LEFT OUTER JOIN sandharbh_master sm ON i.ltr_type=sm.sandhrbh_id
								where  t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								GROUP BY sandharbh_nm");
								$rsut=mysql_query($qre) or die("".mysql_error());*/
								
								echo " <table id='dyntable' class='table table-bordered'>
								<thead>
								<tr>
								<th class='head0 center' style='width:160px;'>संदर्भाचे नाव </th>
								<th class='head1 center'>एकूण </th>
								</tr>
								</thead>";
								$query=("SELECT * FROM sandharbh_master");
					$rsut0=mysql_query($query) or die("".mysql_error());
					
						$c=0;
					while($row = mysql_fetch_array($rsut0))
					{
						$sid=$row['sandhrbh_id'];
						//dept accepted nd not returned nd deskid=0 or approval=pending
						$qre=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
						where t.ltr_id=i.ltr_id
						AND  t.dept_id_from=(select dept_id from login where login_id='$username') 
						AND t.returned_choice=''
						AND (t.desk_id='0' OR t.desk_approval='pending')
						AND i.ltr_type='$sid' ");
						$rsut=mysql_query($qre) or die("".mysql_error());
						
						//desk accptd nd ltr_status!=closed
						$qree=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i , tapal_to_dpt_transaction t, desk_transaction de  
						where t.ltr_id=i.ltr_id
						AND de.dpt_ltr_id = t.dpt_ltr_id
						AND t.dept_id_from=(select dept_id from login where login_id='$username') 
						AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
						AND i.ltr_type='$sid' ");
						$rsut1=mysql_query($qree) or die("".mysql_error());
						
						
						$i=0;
						$j=0;
						
						while($rws = mysql_fetch_array($rsut))
						{
							$arr[$i]=$rws['TOTAL'];
							//echo $arr[$i];
						
						}
						while($rws1 = mysql_fetch_array($rsut1))
						{
							$arr1[$j]=$rws1['TOTAL'];
							//echo $arr1[$j];
							
						}
						$arr2[$c]=$arr[$i]+$arr1[$j];
						echo "<td class='center'><a href='report_dpt_sandharbha.php?ltr_id=$sid&no=1'>".$row['sandharbh_nm']."</a></td><td>". $arr2[$c]."</td> </tr>";
							$i++;
							$j++;
							$c++;
					}
								
								?>
								</tbody>
								</table>
								<?php 
								echo "<div id='divToPrint' style='display:none;'>";
								convert_marathi();
							/*	$qre=("SELECT tapal_to_dpt_transaction.dept_id_from, incoming_letters_transaction.ltr_type, sandharbh_master.sandharbh_nm, COUNT(*) AS TOTAL FROM incoming_letters_transaction, sandharbh_master, tapal_to_dpt_transaction WHERE 
								tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id AND
								incoming_letters_transaction.ltr_type=sandharbh_master.sandhrbh_id AND incoming_letters_transaction.dept_id=(select dept_id from login where login_id='$username') GROUP BY sandharbh_nm");
								$qre=("SELECT t.dept_id_from, i.ltr_type, sm.sandharbh_nm, COUNT(*) AS TOTAL 
								FROM incoming_letters_transaction i,sandharbh_master sm,tapal_to_dpt_transaction t 
								where t.ltr_id=i.ltr_id 
								AND i.ltr_type=sm.sandhrbh_id  
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								GROUP BY sandharbh_nm"); 
																
								$rsut=mysql_query($qre) or die("".mysql_error());*/
								echo "<center><table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='8'><center><h4>".$rsz['dept_nm']. "चे संदर्भनुसार रिपोर्ट्स   </h4></center></td></tr>
								<tr>
								<th>संदर्भाचे नाव </th>
								<th>एकूण </th>
								</tr>";
								echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
								
							$query=("SELECT * FROM sandharbh_master");
					$rsut0=mysql_query($query) or die("".mysql_error());
					
						$c=0;
					while($row = mysql_fetch_array($rsut0))
					{
						$sid=$row['sandhrbh_id'];
						//dept accepted nd not returned nd deskid=0 or approval=pending
						$qre=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
						where t.ltr_id=i.ltr_id
						AND  t.dept_id_from=(select dept_id from login where login_id='$username') 
						AND t.returned_choice=''
						AND (t.desk_id='0' OR t.desk_approval='pending')
						AND i.ltr_type='$sid' ");
						$rsut=mysql_query($qre) or die("".mysql_error());
						
					//desk accptd nd ltr_status!=closed
						$qree=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i , tapal_to_dpt_transaction t, desk_transaction de  
						where t.ltr_id=i.ltr_id
						AND de.dpt_ltr_id = t.dpt_ltr_id
						AND t.dept_id_from=(select dept_id from login where login_id='$username') 
						AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
						AND i.ltr_type='$sid' ");
						$rsut1=mysql_query($qree) or die("".mysql_error());
						
						
						$i=0;
						$j=0;
						
						while($rws = mysql_fetch_array($rsut))
						{
							$arr[$i]=$rws['TOTAL'];
							//echo $arr[$i];
						
						}
						while($rws1 = mysql_fetch_array($rsut1))
						{
							$arr1[$j]=$rws1['TOTAL'];
							//echo $arr1[$j];
							
						}
						$arr2[$c]=$arr[$i]+$arr1[$j];
						echo "<td class='center'>".$row['sandharbh_nm']."</td><td>". $arr2[$c]."</td> </tr>";
							$i++;
							$j++;
							$c++;
					}
								echo "</table></center></div>";
							} 
					
							else if($ltrid != "")
							{
								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 action='' method='post'>";
							$date123	= $_POST['start_date'];
							$date1	= date('Y-m-d',strtotime($date123));
							$date223	= $_POST['end_date'];
							$date2	= date('Y-m-d',strtotime($date223));
							//$date22	= date('d-m-Y',strtotime($date2));
							if($date123==''&& $date223=='')
							{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id1 = $date1;
								$id2= $date2;
								/*$result222=mysql_query("SELECT * FROM incoming_letters_transaction, tapal_to_dpt_transaction WHERE incoming_letters_transaction.ltr_type='$ltrid' AND incoming_letters_transaction.dept_id=(select dept_id from login where login_id='$username') AND incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id") or die("abc".mysql_error());*/
								
								//dept accepted nd not returned nd deskid=0 or desk approval=pending
								$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.sent_to_desk_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, 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.ltr_id=i.ltr_id
								AND  t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								AND (t.desk_id='0' OR t.desk_approval='pending')
								AND i.ltr_type='$ltrid' ") or die("abc".mysql_error());
								
								//desk accptd nd ltr_status!=closed
								$result2221=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.sent_to_desk_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, 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.ltr_id=i.ltr_id
								AND de.dpt_ltr_id = t.dpt_ltr_id
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND i.ltr_type='$ltrid' ") or die("abc".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;
								/*$result222=mysql_query("SELECT * FROM incoming_letters_transaction, tapal_to_dpt_transaction WHERE incoming_letters_transaction.ltr_type='$ltrid' AND incoming_letters_transaction.dept_id=(select dept_id from login where login_id='$username') AND incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND (incoming_letters_transaction.receive_dt BETWEEN '$date1' AND '$date2')") or die("ccc".mysql_error());*/
								$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.sent_to_desk_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, 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.ltr_id=i.ltr_id
								AND  t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								AND (t.desk_id='0' OR t.desk_approval='pending')
								AND i.ltr_type='$ltrid' 
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("abc".mysql_error());
								
								$result2221=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.sent_to_desk_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, 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.ltr_id=i.ltr_id
								AND de.dpt_ltr_id = t.dpt_ltr_id
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND i.ltr_type='$ltrid'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("abc".mysql_error());
							}
								$count10=mysql_num_rows($result222);
			
								echo "<table id='dyntable' class='table table-bordered'>		
								<thead>
								<tr>
								<th class='head0 center'>पोलीस अधिक्षक कार्यालय<br> आवक_क्रमांक <br>व_दिनांक</th>
								<th class=''head1 center'>संदर्भ क्रमांक<br>व_दिनांक</th>
								<th class='head1 center'>विषय</th>
								<th class='head0 center'>कोणाकडून प्राप्त झाला</th>";
								//echo "<th class='head1 center'>प्राधान्य दिवस </th>";
								
								echo "<th class='head0 center'>डेस्कला  पाठवले </th>
								<th class='head1 center'>डेस्कला_संदर्भ पाठवलेली_दिनांक </th>
								<th class='head0 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']=='')
									{
										$dis_date="डेस्कला पाठविणे बाकी" ;	
									}
									else
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									}
					
									$id1 = $test['ltr_inword_no'];
									$id2 = $test['assign_dpt'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$to_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['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=1>".$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());
									while($rw09=mysql_fetch_array($rs09))
									{
										$desknm=$rw09['desk_nm'];
									}
									
									$qry091="Select desk_nm from desk_master where desk_id='$to_deskid'";
									$rs091=mysql_query($qry091) or die("sss".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									///////////////////////////////////////////////////////////
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'> डेस्क लावणे बाकी </font></td>";
									}
									else if($test['desk_approval']=='pending')
									{
										echo "<td class='center'><font color='red'>".$rw091['desk_nm']."<br> डेस्कने स्वीकारणे बाकी </font></td>";
									}
									else 
									{
										echo "<td class='center'>".$desknm."</td>";
									}
									/////////////////////////////////////////////////////
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'> डेस्क लावणे बाकी </font></td>";
									}
									else
									{
										echo "<td class='center'>".$dis_date."</font></td>";
									}
									//////////////////////////////////////////////
									if($test['ltr_status']=='' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									/////////////////////////////////////////////////////
									echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></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']=='')
									{
										$dis_date="डेस्कला पाठविणे बाकी" ;	
									}
									else
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									}
					
									$id1 = $test['ltr_inword_no'];
									$id2 = $test['assign_dpt'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$to_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['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=1>".$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());
									while($rw09=mysql_fetch_array($rs09))
									{
										$desknm=$rw09['desk_nm'];
									}
									
									$qry091="Select desk_nm from desk_master where desk_id='$to_deskid'";
									$rs091=mysql_query($qry091) or die("sss".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									///////////////////////////////////////////////////////////
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'> डेस्क लावणे बाकी </font></td>";
									}
									else if($test['desk_approval']=='pending')
									{
										echo "<td class='center'><font color='red'>".$rw091['desk_nm']."<br> डेस्कने स्वीकारणे बाकी </font></td>";
									}
									else 
									{
										echo "<td class='center'>".$desknm."</td>";
									}
									/////////////////////////////////////////////////////
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'><font color='red'> डेस्क लावणे बाकी </font></td>";
									}
									else
									{
										echo "<td class='center'>".$dis_date."</font></td>";
									}
									//////////////////////////////////////////////
									if($test['ltr_status']=='' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									///////////////////////////////////////////////////
									if($test['ltr_approval']=='transferred' )
									{
										$todept=$test['dept_id_to'];
										$q=mysql_query("SELECT dept_nm from department_master where dept_id='$todept' ");
										$r=mysql_fetch_array($q);
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$r['dept_nm']." </td>";
									}
									else if($test['ltr_status']=='updated')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='dispatched')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else
									{
										echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></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> ".$rsz['dept_nm']. "चे संदर्भनुसार रिपोर्ट्स ( ".$rs['sandharbh_nm']." )   <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
								echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
							if($date123==''&& $date223=='')
							{
								$id1 = $date1;
								$id2= $date2;
								
								//dept accepted nd not returned nd deskid=0 or desk approval=pending
								$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.sent_to_desk_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, 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.ltr_id=i.ltr_id
								AND  t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								AND (t.desk_id='0' OR t.desk_approval='pending')
								AND i.ltr_type='$ltrid' ") or die("abc".mysql_error());
								
								//desk accptd nd ltr_status!=closed
								$result2221=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.sent_to_desk_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, 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.ltr_id=i.ltr_id
								AND de.dpt_ltr_id = t.dpt_ltr_id
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND de.ltr_status!='closed' AND de.ltr_approval!='transferred_todesk'
								AND i.ltr_type='$ltrid' ") or die("abc".mysql_error());
								
							}
							else{
								$id = $date1;
								$id1= $date2;
								
								$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.sent_to_desk_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, 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.ltr_id=i.ltr_id
								AND  t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								AND (t.desk_id='0' OR t.desk_approval='pending')
								AND i.ltr_type='$ltrid' 
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("abc".mysql_error());
								
								$result2221=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.sent_to_desk_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, 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.ltr_id=i.ltr_id
								AND de.dpt_ltr_id = t.dpt_ltr_id
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND de.ltr_status!='closed'
								AND i.ltr_type='$ltrid' AND de.ltr_approval!='transferred_todesk'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("abc".mysql_error());
							}
								$count10=mysql_num_rows($result222);
			
								echo "
								<tr>
								<th class='head0 center'>पोलीस अधिक्षक कार्यालय<br> आवक_क्रमांक <br>व_दिनांक</th>
								<th class=''head1 center'>संदर्भ क्रमांक<br>व_दिनांक</th>
								<th class='head1 center'>विषय</th>
								<th class='head0 center'>कोणाकडून प्राप्त झाला</th>";
								//echo "<th class='head1 center'>प्राधान्य दिवस </th>";
								
								echo "<th class='head0 center'>डेस्कला  पाठवले </th>
								<th class='head1 center'>डेस्कला_संदर्भ पाठवलेली_दिनांक </th>
								<th class='head0 center'>केलेली कार्यवाही</th>
								<th class='head0 center'>पत्राची स्थिती </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']=='')
									{
										$dis_date="डेस्कला पाठविणे बाकी" ;	
									}
									else
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									}
					
									$id1 = $test['ltr_inword_no'];
									$id2 = $test['assign_dpt'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$to_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['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=1>".$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());
									while($rw09=mysql_fetch_array($rs09))
									{
										$desknm=$rw09['desk_nm'];
									}
									
									$qry091="Select desk_nm from desk_master where desk_id='$to_deskid'";
									$rs091=mysql_query($qry091) or die("sss".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									///////////////////////////////////////////////////////////
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'> डेस्क लावणे बाकी </td>";
									}
									else if($test['desk_approval']=='pending')
									{
										echo "<td class='center'>".$rw091['desk_nm']."<br> डेस्कने स्वीकारणे बाकी </td>";
									}
									else 
									{
										echo "<td class='center'>".$desknm."</td>";
									}
									/////////////////////////////////////////////////////
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'> डेस्क लावणे बाकी </td>";
									}
									else
									{
										echo "<td class='center'>".$dis_date."</font></td>";
									}
									//////////////////////////////////////////////
									if($test['ltr_status']=='' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'> कार्यवाही करणे बाकी </td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									/////////////////////////////////////////////////////
									echo "<td class='center'> कार्यवाही करणे बाकी </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']=='')
									{
										$dis_date="डेस्कला पाठविणे बाकी" ;	
									}
									else
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									}
					
									$id1 = $test['ltr_inword_no'];
									$id2 = $test['assign_dpt'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id_from'];
									$to_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['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=1>".$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());
									while($rw09=mysql_fetch_array($rs09))
									{
										$desknm=$rw09['desk_nm'];
									}
									
									$qry091="Select desk_nm from desk_master where desk_id='$to_deskid'";
									$rs091=mysql_query($qry091) or die("sss".mysql_error());
									$rw091=mysql_fetch_array($rs091);
									///////////////////////////////////////////////////////////
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'> डेस्क लावणे बाकी </td>";
									}
									else if($test['desk_approval']=='pending')
									{
										echo "<td class='center'>".$rw091['desk_nm']."<br> डेस्कने स्वीकारणे बाकी </td>";
									}
									else 
									{
										echo "<td class='center'>".$desknm."</td>";
									}
									/////////////////////////////////////////////////////
									if($test['desk_id']=='' || $test['desk_id']=='0')
									{
										echo "<td class='center'> डेस्क लावणे बाकी </td>";
									}
									else
									{
										echo "<td class='center'>".$dis_date."</font></td>";
									}
									//////////////////////////////////////////////
									if($test['ltr_status']=='' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'> कार्यवाही करणे बाकी </td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									///////////////////////////////////////////////////
									if($test['ltr_approval']=='transferred' )
									{
										$todept=$test['dept_id_to'];
										$q=mysql_query("SELECT dept_nm from department_master where dept_id='$todept' ");
										$r=mysql_fetch_array($q);
										echo "<td class='center'>".$test['ltr_approval']." to <br>".$r['dept_nm']." </td>";
									}
									else if($test['ltr_status']=='updated')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else if($test['ltr_status']=='dispatched')
									{
										echo "<td class='center'>".$test['ltr_status']."</td>";
									}
									else
									{
										echo "<td class='center'> कार्यवाही करणे बाकी </td>";
									}
									
									echo "</tr>";
								}
							//mysql_close();
							echo "</table></center></div>";
							
		}					
?><br>
					<p>	
						<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
						<input type="button" class="btn" onclick="tableToExcel('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 Sandharbh Wise Report For Department User #################################

##################################### Sandharbh Wise Report For BDO User #######################################################
else if($no==3)
{
$username = $_SESSION['User_Name'];
include('dashboard_bdo.php');	
/*****************************
BDO
******************************/
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript">     
function PrintDiv() {    
var divToPrint = document.getElementById('divToPrint');
var popupWin = window.open('', '_blank', 'width=600,height=600');
popupWin.document.open();
popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
popupWin.document.close();
}
</script> 
<script src="tableToExcel.js"></script>
</head>
<body>
<div class="mainwrapper">   
    <div class="rightpanel">
        <ul class="breadcrumbs">
            <li><a href=""><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="">Tables</a> <span class="separator"></span></li>
            <li>संदर्भ प्रकारानुसार  रिपोर्ट्स</li>
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
			<div class="pagetitle">
				<h5>Tables</h5>
				<?php 
					$qryz=mysql_query("Select dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
					$rsz=mysql_fetch_array($qryz);
					
					$qry=mysql_query("Select sandharbh_nm from sandharbh_master where sandhrbh_id='$ltrid' ");
					$rs=mysql_fetch_array($qry);
				?>
				<h1><?php echo 	$rsz['dept_nm'];?>संदर्भ प्रकारानुसार  रिपोर्ट्स</h1>
			</div>
		</div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
			    <h4 class="widgettitle"><?php echo 	$rsz['dept_nm'];?>संदर्भ प्रकारानुसार  रिपोर्ट्स  (  <?php echo $rs['sandharbh_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 		
				if($ltrid=="" && $no==3)
				{
					    convert_marathi();
						echo "<table id='dyntable' class='table table-bordered'>		
								<thead>
								<tr>
								<th class='head0 center' style='width:160px;'>संदर्भाचे नाव </th>
								<th class='head1 center'>एकूण </th>
								</tr>
								</thead>";
						
				$query=("SELECT * FROM sandharbh_master");
					$rsut0=mysql_query($query) or die("".mysql_error());
					
						$c=0;
					while($row = mysql_fetch_array($rsut0))
					{
						$sid=$row['sandhrbh_id'];
						
						/*/////////////dept accepted ltr///////
						$qre=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
						where t.ltr_id=i.ltr_id
						AND i.ltr_type='$sid'
						AND i.status='approve' ");
						$rsut=mysql_query($qre) or die("".mysql_error());
						
						//////////dept not accepted ltr/////////////
						$qree=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i
						where i.status='pending'
						AND i.ltr_type='$sid' ");
						$rsut1=mysql_query($qree) or die("".mysql_error());*/
						
						///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
						$result222=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
						WHERE t.ltr_id=i.ltr_id
						AND i.ltr_type='$sid'
						AND t.returned_choice=''
						AND (t.desk_id='0' OR t.desk_approval='pending')
						AND t.status!='transferred' ") or die("sdfdfds".mysql_error());
						$rsut=mysql_query($result222) or die("ccc".mysql_error());
													
						/////// not assigned dept or not accepted by dept//////////
						$result2223=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i
						where (i.status='pending' || i.dept_id='0')
						AND i.ltr_type='$sid'") or die("sdfdfds".mysql_error());
						$rsut1=mysql_query($result2223) or die("bbb".mysql_error());
													
						///////desk accpted ltrs ecept transferred ane returnd///////
						$result22231=("SELECT COUNT(*) AS TOTAL 
						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 i.ltr_type='$sid'
						AND de.ltr_status!='closed'
						AND de.ltr_approval!='transferred' AND de.ltr_approval!='transferred_todesk' ") or die("sdfdfds".mysql_error());
						$rsut2=mysql_query($result22231) or die("aaa".mysql_error());	
						
						
						$i=0;
						$j=0;
						$k=0;
						
						while($rws = mysql_fetch_array($rsut))
						{
							$arr[$i]=$rws['TOTAL'];
							//echo $arr[$i];
						
						}
						while($rws1 = mysql_fetch_array($rsut1))
						{
							$arr1[$j]=$rws1['TOTAL'];
							//echo $arr1[$j];
							
						}
						while($rws2 = mysql_fetch_array($rsut2))
						{
							$arr2[$k]=$rws2['TOTAL'];
							//echo $arr1[$j];
							
						}
						$arr3[$c]=$arr[$i]+$arr1[$j]+$arr2[$k];
						echo "<td class='center'><a href='report_dpt_sandharbha.php?ltr_id=$sid&no=3'>".$row['sandharbh_nm']."</a></td><td>". $arr3[$c]."</td> </tr>";
							$i++;
							$j++; 
							$k++;
							$c++;
					}
					?>
					</tbody>
					</table>
							<?php
							echo "<div id='divToPrint' style='display:none;'>
							<center><table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='8'><center><h4>".	$rsz['dept_nm']."संदर्भ प्रकारानुसार  रिपोर्ट्स <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
							echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
								convert_marathi();
								$query=("SELECT * FROM sandharbh_master");
					$rsut0=mysql_query($query) or die("".mysql_error());
					
						$c=0;
					while($row = mysql_fetch_array($rsut0))
					{
						$sid=$row['sandhrbh_id'];
						
						///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
						$result222=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
						WHERE t.ltr_id=i.ltr_id
						AND i.ltr_type='$sid'
						AND t.returned_choice=''
						AND (t.desk_id='0' OR t.desk_approval='pending') 
						AND t.status!='transferred' ") or die("sdfdfds".mysql_error());
						$rsut=mysql_query($result222) or die("ccc".mysql_error());
													
						/////// not assigned dept or not accepted by dept//////////
						$result2223=("SELECT COUNT(*) AS TOTAL 
						FROM incoming_letters_transaction i
						where (i.status='pending' || i.dept_id='0')
						AND i.ltr_type='$sid'") or die("sdfdfds".mysql_error());
						$rsut1=mysql_query($result2223) or die("bbb".mysql_error());
													
						///////desk accpted ltrs ecept transferred ane returnd///////
						$result22231=("SELECT COUNT(*) AS TOTAL 
						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 i.ltr_type='$sid'
						AND de.ltr_status!='closed'
						AND de.ltr_approval!='transferred' AND de.ltr_approval!='transferred_todesk' ") or die("sdfdfds".mysql_error());
						$rsut2=mysql_query($result22231) or die("aaa".mysql_error());	
						
						
						$i=0;
						$j=0;
						$k=0;
						
						while($rws = mysql_fetch_array($rsut))
						{
							$arr[$i]=$rws['TOTAL'];
							//echo $arr[$i];
						
						}
						while($rws1 = mysql_fetch_array($rsut1))
						{
							$arr1[$j]=$rws1['TOTAL'];
							//echo $arr1[$j];
							
						}
						while($rws2 = mysql_fetch_array($rsut2))
						{
							$arr2[$k]=$rws2['TOTAL'];
							//echo $arr1[$j];
							
						}
						$arr3[$c]=$arr[$i]+$arr1[$j]+$arr2[$k];
						echo "<td class='center'>".$row['sandharbh_nm']."</td><td class='center' width='80'>". $arr3[$c]."</td> </tr>";
							$i++;
							$j++; 
							$k++;
							$c++;
					}
					echo "</table></center></div>";	
								
					} 	
					else if( $ltrid != "" && $no==3)
					{ 
						convert_marathi();		
						$date123	= $_POST['start_date'];
						$date1	= date('Y-m-d',strtotime($date123));
						$date223	= $_POST['end_date'];
						$date2	= date('Y-m-d',strtotime($date223));
						//$date22	= date('d-m-Y',strtotime($date2));
						if($date123==''&& $date223=='')
						{
							echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
							$id1 = $date1;
							$id2= $date2;
							
							///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
							$result222=mysql_query("SELECT * FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
							WHERE t.ltr_id=i.ltr_id
							AND i.ltr_type='$ltrid'
							AND t.returned_choice=''
							AND (t.desk_id='0' OR t.desk_approval='pending')
							AND t.status!='transferred' ") or die("sdfdfds".mysql_error());
							
							/////// not assigned dept or not accepted by dept//////////
							$result2223=mysql_query("SELECT * FROM incoming_letters_transaction i
							where (i.status='pending' || i.dept_id='0')
							AND i.ltr_type='$ltrid'") or die("sdfdfds".mysql_error());
							
							///////desk accpted ltrs except transferred ane returnd///////
							$result22231=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
							WHERE i.ltr_type='$ltrid'
							AND de.ltr_status!='closed' 
							AND de.ltr_approval!='transferred'
							AND de.ltr_approval!='transferred_todesk'") 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;
							
							///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
							$result222=mysql_query("SELECT * FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
							WHERE t.ltr_id=i.ltr_id
							AND i.ltr_type='$ltrid'
							AND t.returned_choice=''
							AND (t.desk_id='0' OR t.desk_approval='pending')
							AND t.status!='transferred'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
							/////// not assigned dept or not accepted by dept//////////
							$result2223=mysql_query("SELECT * FROM incoming_letters_transaction i
							where (i.status='pending' || i.dept_id='0')
							AND i.ltr_type='$ltrid'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
							///////desk accpted ltrs ecept transferred ane returnd///////
							$result22231=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
							WHERE i.ltr_type='$ltrid'
							AND de.ltr_status!='closed'
							AND de.ltr_approval!='transferred' AND de.ltr_approval!='transferred_todesk'
							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>व_दिनांक</th>
                            <th class='head1 center'>संदर्भ <br>क्रमांक_व_दिनांक</th>
							<th class=head1 center> विभाग आवक_क्रमांक <br>व_दिनांक</th>
                            <th class='head1 center'>विषय</th>
							<th class='head0 center'>कोणाकडून प्राप्त झाला</th>";
							//echo "<th class='head1 center'>प्राधान्य दिवस </th>";
							echo "<th class='head0 center'>विभाग पाठवले </th>	";
							
							//echo  "<th class='head0 center'>विभागाला_संदर्भ पाठवलेली_दिनांक </th>";
							echo "</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']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test['ltr_inward_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$deptid=$test['dept_id_from'];
				
								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>".$dept_rec_date."</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 dept_nm from department_master where dept_id='$deptid'";
								$rs09=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw09=mysql_fetch_array($rs09))
								{
									$deptnm=$rw09['dept_nm'];
								}
								if($deptnm!='')
								{
									echo "<td class='center'><a href=report_dptwise.php?no=3&dept_id=$deptid>".$deptnm."</a></td>";
								}
								else if($deptnm=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
							
							while($test1 = mysql_fetch_array($result2223))
							{
								$ref_date 		= date('d-m-Y',strtotime($test1['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test1['receive_dt']));
								//$dept_rec_date 		= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test1['ltr_inward_no'];
								$id2 = $test1['assign_dept'];
								$id3 = $test1['sandarbh_prakar'];
								$deptid=$test1['dept_id'];
				
								echo "<tr class='gradeX'>
								<td class='center'>".$test1['ltr_inword_no']."<br>".$rec_date ."</td>
								<td class='center'>".$test1['ref_no']."</font><br>".$ref_date."</td>";
								
								if($test1['dept_id']=='0' || $test1['dept_id']=='')
								{
									echo "<td class='center'><font color='red'> विभाग लावणे बाकी  </font></td>";
								}
								else
								{
									echo "<td class='center'><font color='red'> विभागाने स्वीकारणे बाकी  </font></td>";
								}
								echo "<td class='center'>".$test1['subject']."</td>
								<td class='center'>".$test1['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 dept_nm from department_master where dept_id='$deptid'";
								$rs091=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw091=mysql_fetch_array($rs091))
								{
									$deptnm1=$rw091['dept_nm'];
								}
								if($deptnm1!='')
								{
									echo "<td class='center'><a href=report_dptwise.php?no=3&dept_id=$deptid>".$deptnm1."</a></td>";
								}
								else if($deptnm1=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
							while($test = mysql_fetch_array($result22231))
							{
								$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test['ltr_inward_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$deptid=$test['dept_id_from'];
				
								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>".$dept_rec_date."</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 dept_nm from department_master where dept_id='$deptid'";
								$rs09=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw09=mysql_fetch_array($rs09))
								{
									$deptnm=$rw09['dept_nm'];
								}
								if($deptnm!='')
								{
									echo "<td class='center'><a href=report_dptwise.php?no=3&dept_id=$deptid>".$deptnm."</a></td>";
								}
								else if($deptnm=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></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> संदर्भनुसार रिपोर्ट्स (  ".$rs['sandharbh_nm']." )<br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
						
						echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
						convert_marathi();			
						if($date123==''&& $date223=='')
						{
							$id1 = $date1;
							$id2= $date2;
							
							///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
							$result222=mysql_query("SELECT * FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
							WHERE t.ltr_id=i.ltr_id
							AND i.ltr_type='$ltrid'
							AND t.returned_choice=''
							AND (t.desk_id='0' OR t.desk_approval='pending')
							AND t.status!='transferred' ") or die("sdfdfds".mysql_error());
							
							/////// not assigned dept or not accepted by dept//////////
							$result2223=mysql_query("SELECT * FROM incoming_letters_transaction i
							where (i.status='pending' || i.dept_id='0')
							AND i.ltr_type='$ltrid'") or die("sdfdfds".mysql_error());
							
							///////desk accpted ltrs ecept transferred ane returnd///////
							$result22231=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
							WHERE i.ltr_type='$ltrid'
							AND de.ltr_status!='closed'
							AND de.ltr_approval!='transferred'
							AND de.ltr_approval!='transferred_todesk' ") or die("sdfdfds".mysql_error());
							
						}
						else{
							$id1 = $date1;
							$id2= $date2;
							
							///////accepted by dept but not return to tapal and assigned desk,desk not accepted or not assigned desk//////////
							$result222=mysql_query("SELECT * FROM incoming_letters_transaction i,tapal_to_dpt_transaction t
							WHERE t.ltr_id=i.ltr_id
							AND i.ltr_type='$ltrid'
							AND t.returned_choice=''
							AND (t.desk_id='0' OR t.desk_approval='pending')
							AND t.status!='transferred'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
							/////// not assigned dept or not accepted by dept//////////
							$result2223=mysql_query("SELECT * FROM incoming_letters_transaction i
							where (i.status='pending' || i.dept_id='0')
							AND i.ltr_type='$ltrid'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
							///////desk accpted ltrs ecept transferred ane returnd///////
							$result22231=mysql_query("SELECT DISTINCT de.desk_ltr_id,i.ltr_type, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id,t.returned_choice, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
							WHERE i.ltr_type='$ltrid'
							AND de.ltr_status!='closed'
							AND de.ltr_approval!='transferred' AND de.ltr_approval!='transferred_todesk'
							AND (i.receive_dt BETWEEN '$date1' AND '$date2') ") or die("sdfdfds".mysql_error());
							
						}
						$count10=mysql_num_rows($result222);
						echo "	
							<tr>
                           <th class='head0 center'>पोलीस अधिक्षक कार्यालय<br> आवक_क्रमांक <br>व_दिनांक</th>
                            <th class='head1 center'>संदर्भ <br>क्रमांक_व_दिनांक</th>
							<th class=head1 center> विभाग आवक_क्रमांक <br>व_दिनांक</th>
                            <th class='head1 center'>विषय</th>
							<th class='head0 center'>कोणाकडून प्राप्त झाला</th>";
							//echo "<th class='head1 center'>प्राधान्य दिवस </th>";
							echo "<th class='head0 center'>विभाग पाठवले </th>	";
							
							//echo  "<th class='head0 center'>विभागाला_संदर्भ पाठवलेली_दिनांक </th>";
							echo "</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']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test['ltr_inward_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$deptid=$test['dept_id_from'];
				
								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>".$dept_rec_date."</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 dept_nm from department_master where dept_id='$deptid'";
								$rs09=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw09=mysql_fetch_array($rs09))
								{
									$deptnm=$rw09['dept_nm'];
								}
								if($deptnm!='')
								{
									echo "<td class='center'>".$deptnm."</td>";
								}
								else if($deptnm=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
							
							while($test1 = mysql_fetch_array($result2223))
							{
								$ref_date 		= date('d-m-Y',strtotime($test1['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test1['receive_dt']));
								//$dept_rec_date 		= date('d-m-Y',strtotime($test1['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test1['ltr_inward_no'];
								$id2 = $test1['assign_dept'];
								$id3 = $test1['sandarbh_prakar'];
								$deptid=$test1['dept_id'];
				
								echo "<tr class='gradeX'>
								<td class='center'>".$test1['ltr_inword_no']."<br>".$rec_date ."</td>
								<td class='center'>".$test1['ref_no']."</font><br>".$ref_date."</td>";
								
								if($test1['dept_id']=='0' || $test1['dept_id']=='')
								{
									echo "<td class='center'> विभाग लावणे बाकी  </td>";
								}
								else
								{
									echo "<td class='center'> विभागाने स्वीकारणे बाकी  </td>";
								}
								echo "<td class='center'>".$test1['subject']."</td>
								<td class='center'>".$test1['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 dept_nm from department_master where dept_id='$deptid'";
								$rs091=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw091=mysql_fetch_array($rs091))
								{
									$deptnm1=$rw091['dept_nm'];
								}
								if($deptnm1!='')
								{
									echo "<td class='center'>".$deptnm1."</td>";
								}
								else if($deptnm1=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
							while($test = mysql_fetch_array($result22231))
							{
								$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
								$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								/*if($test['sent_to_desk_dt']=='')
								{
									$dis_date = date('d-m-Y',strtotime($test['sent_dt']));
								}
								else
								{
									$dis_date="--" ;			
								} */
								
								$id1 = $test['ltr_inward_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$deptid=$test['dept_id_from'];
				
								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>".$dept_rec_date."</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 dept_nm from department_master where dept_id='$deptid'";
								$rs09=mysql_query($qry09) or die("assssss".mysql_error());
								while($rw09=mysql_fetch_array($rs09))
								{
									$deptnm=$rw09['dept_nm'];
								}
								if($deptnm!='')
								{
									echo "<td class='center'>".$deptnm."</td>";
								}
								else if($deptnm=='')
								{
									echo "<td class='center'>--</td>";
								}
								//echo "<td class='center'>".$dis_date."</font></td>";
								
								echo "</tr>";
							}
							//mysql_close();
						echo" </table></center></div>";
					}
					?>
					<br>
					<p>	
						<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
						<input type="button" class="btn" onclick="tableToExcel('export', 'W3C Example Table')" value="Export to Excel"></center>
					</p>
				</form>
				   </div><!--maincontentinner-->
        
                        <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php
}
##################################### End Of Sandharbh Wise Report For BDO User ###################################
} //if($flag=='')

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

else if($flag=='n')
{
require_once('convert_marathi.php');
$no=$_GET['no'];
$ltrid=$_REQUEST['ltr_id'];

############################ Sandharbh Wise Report For Department User ########################################
if($no=='1')
{
$username = $_SESSION['User_Name'];	
include('new_dashboard_department.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="">Tables</a> <span class="separator"></span></li>
            <li>संदर्भनुसार रिपोर्ट्स</li> 
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
                <?php 
				$qryz=mysql_query("Select dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
				$rsz=mysql_fetch_array($qryz);
				
				$qry=mysql_query("Select sandharbh_nm from sandharbh_master where sandhrbh_id='$ltrid' ");
				$rs=mysql_fetch_array($qry);
				?>
                <h1><?php echo 	$rsz['dept_nm'];?>चे संदर्भनुसार रिपोर्ट्स </h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
					<h4 class="widgettitle"> <?php echo $rsz['dept_nm'];?>चे संदर्भनुसार रिपोर्ट्स ( <?php echo $rs['sandharbh_nm']; ?> ) </h4>
					<form method="post" action="">
						<?php 		
						if($ltrid=="")
						{
								convert_marathi();
								$qre=("SELECT t.dept_id_from, i.ltr_type, sm.sandharbh_nm, COUNT(*) AS TOTAL 
								FROM incoming_letters_transaction i,sandharbh_master sm,tapal_to_dpt_transaction t 
								where t.ltr_id=i.ltr_id 
								AND i.ltr_type=sm.sandhrbh_id  
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								GROUP BY sandharbh_nm"); 
																
								$rsut=mysql_query($qre) or die("".mysql_error());
								echo " <table id='dyntable' class='table table-bordered'>
								<thead>
								<tr>
								<th class='head0 center' style='width:160px;'>संदर्भाचे नाव </th>
								<th class='head1 center'>एकूण </th>
								</tr>
								</thead>";
								while($rws = mysql_fetch_array($rsut))
								{
									$ltr_id=$rws['ltr_type'];
									?>
									<tbody>
									<tr class="gradeX">
									<?php 
									echo "<td class='center'><a href='report_dpt_sandharbha.php?flag=n&ltr_id=$ltr_id&no=1'>".$rws['sandharbh_nm']."</a></td>	<td class='center'>". $rws['TOTAL']."</td> </tr>";                 
								}
								
								?>
								</tbody>
								</table>
								<?php 
								echo "<div id='divToPrint' style='display:none;'>";
								convert_marathi();
								$qre=("SELECT t.dept_id_from, i.ltr_type, sm.sandharbh_nm, COUNT(*) AS TOTAL 
								FROM incoming_letters_transaction i,sandharbh_master sm,tapal_to_dpt_transaction t 
								where t.ltr_id=i.ltr_id 
								AND i.ltr_type=sm.sandhrbh_id  
								AND t.dept_id_from=(select dept_id from login where login_id='$username')
								AND t.returned_choice=''
								GROUP BY sandharbh_nm"); 
								
								$rsut=mysql_query($qre) or die("".mysql_error());
								echo " <center><table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='8'><center><h4>".$rsz['dept_nm']. "चे संदर्भनुसार रिपोर्ट्स   </h4></center></td></tr>
								<tr>
								<th>संदर्भाचे नाव </th>
								<th>एकूण </th>
								</tr>";
								echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
								while($rws = mysql_fetch_array($rsut))
								{
									$ltr_id=$rws['ltr_type'];
									echo "<tr>
									<td style='text-align:center;'>".$rws['sandharbh_nm']."</td><td style='text-align:center;'>". $rws['TOTAL']."</td></tr>";                 
								}
								echo "</table> </center></div>";
							} 
					
							else if($ltrid != "")
							{
								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 action='' method='post'>";
							$date123	= $_POST['start_date'];
							$date1	= date('Y-m-d',strtotime($date123));
							$date223	= $_POST['end_date'];
							$date2	= date('Y-m-d',strtotime($date223));
							//$date22	= date('d-m-Y',strtotime($date2));
							if($date123==''&& $date223=='')
							{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id1 = $date1;
								$id2= $date2;
								$result222=mysql_query("SELECT i.ref_dt, i.receive_dt, t.sent_to_desk_dt, i.ltr_inword_no, t.assign_dpt, t.desk_id, i.ref_no, i.subject, i.sender_name, i.priority_days,t.action_taken, t.dpt_ltr_rec_dt,t.dpt_inword_no,t.ltr_status
								FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
								WHERE i.ltr_type='$ltrid' 
								AND t.dept_id_from=(select dept_id from login where login_id='$username')
								AND t.returned_choice=''
								AND i.ltr_id=t.ltr_id") or die("abc".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;
								$result222=mysql_query("SELECT i.ref_dt, i.receive_dt, t.sent_to_desk_dt, i.ltr_inword_no, t.assign_dpt, t.desk_id, i.ref_no, i.subject, i.sender_name, i.priority_days,t.action_taken, t.dpt_ltr_rec_dt,t.dpt_inword_no,t.ltr_status
								FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
								WHERE i.ltr_type='$ltrid' 
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								AND i.ltr_id=t.ltr_id AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("ccc".mysql_error());
							}
								$count10=mysql_num_rows($result222);
			
								/*echo "<table id='dyntable' class='table table-bordered'>		
								<thead>
								<tr>
								<th class='head0 center'>आवक_क्रमांक</th>
								<th class=''head1 center'>संदर्भ पाठवलेली<br>क्रमांक_व_दिनांक</th>
								<th class='head0 center'>संदर्भ प्राप्त दिनांक</th>
								<th class='head1 center'>विषय</th>
								<th class='head0 center'>कोणाकडून प्राप्त झाला</th>
								<th class='head1 center'>प्राधान्य दिवस </th>
								<th class='head0 center'>डेस्कला  पाठवले </th>
								<th class='head1 center'>डेस्कला_संदर्भ पाठवलेली_दिनांक </th>
								</tr>
								</thead>";*/
								echo "<table id='dyntable' class='table table-bordered'>		
										<thead>
											<tr>
												<th class='head0 center'>पोलीस अधिक्षक कार्यालय <br> आवक_क्रमांक <br> व_दिनांक </th>
												<th class=''head1 center'>संदर्भ क्रमांक <br> व_दिनांक</th>
												<th class='head1 center'>विभागीय आवक_क्र. <br>आवक_दिनांक </th>
												<th class='head1 center'>विषय</th>
												<th class='head0 center'>कोणाकडून प्राप्त झाला</th>";
										//	echo "<th class='head1 center'>प्राधान्य दिवस </th>";
											echo "<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']));
									$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									/*if($test['sent_to_desk_dt']=='')
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									}
									else
									{
										$dis_date="डेस्कला पाठविणे बाकी" ;			
									}*/
																	
									$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>".$dept_rec_date."</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?flag=n&id=$test[priority_days]&no=1>".$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());
									while($rw09=mysql_fetch_array($rs09))
									{
										$desknm=$rw09['desk_nm'];
									}
									if($desknm!='')
									{
										echo "<td class='center'>".$desknm."</td>";
									}
									else if($desknm=='')
									{
										echo "<td class='center'><font color='red'>डेस्क लावणे बाकी</font> </td>";
									}
									echo "<td class='center'>".$dis_date."</font></td>";*/
									if($test['ltr_status']=='')
									{
										echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी</font> </td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</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>".$rsz['dept_nm']. "चे संदर्भनुसार रिपोर्ट्स ( ".$rs['sandharbh_nm']." ) <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
							echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
								convert_marathi();
							if($date123==''&& $date223=='')
							{
								$result222=mysql_query("SELECT i.ref_dt, i.receive_dt, t.sent_to_desk_dt, i.ltr_inword_no, t.assign_dpt, t.desk_id, i.ref_no, i.subject, i.sender_name, i.priority_days,t.action_taken, t.dpt_ltr_rec_dt,t.dpt_inword_no,t.ltr_status
								FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
								WHERE i.ltr_type='$ltrid' 
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								AND i.ltr_id=t.ltr_id") or die("sdfdfds".mysql_error());
								$count10=mysql_num_rows($result222);
							}
							else
							{
								$result222=mysql_query("SELECT i.ref_dt, i.receive_dt, t.sent_to_desk_dt, i.ltr_inword_no, t.assign_dpt, t.desk_id, i.ref_no, i.subject, i.sender_name, i.priority_days,t.action_taken, t.dpt_ltr_rec_dt,t.dpt_inword_no,t.ltr_status
								FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
								WHERE i.ltr_type='$ltrid' 
								AND t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND t.returned_choice=''
								AND i.ltr_id=t.ltr_id AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("ccc".mysql_error());
							}
								echo "
										<tr>
											<th class='head0 center'>पोलीस अधिक्षक कार्यालय<br> आवक_क्रमांक <br> व_दिनांक </th>
											<th class='head1 center'>संदर्भ क्रमांक <br> व_दिनांक</th>
											<th class='head1 center'>विभागीय आवक_क्र. <br>आवक_दिनांक </th>
											<th class='head1 center'>विषय</th>
											<th class='head0 center'>कोणाकडून प्राप्त झाला</th>";
									//	echo "<th class='head1 center'>प्राधान्य दिवस </th>";
											echo "<th class='head0 center'>केलेली कार्यवाही</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']));
									$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									/*if($test['sent_to_desk_dt']=='')
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									}
									else
									{
										$dis_date="डेस्कला पाठविणे बाकी" ;			
									}*/
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id'];
									echo "<tr>
									<td style='text-align:center;'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td style='text-align:center;'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>
									<td style='text-align:center;'>".$test['subject']."</td>
									<td style='text-align:center;'>".$test['sender_name']."</td>";
									/*if($test['priority_days']=='0')
									{
										echo "<td style='text-align:center;'>"."--"."</td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td style='text-align:center;'>".$test['priority_days']."</td>";		
									}
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									while($rw09=mysql_fetch_array($rs09))
									{
										$desknm=$rw09['desk_nm'];
									}
									if($desknm!='')
									{
										echo "<td style='text-align:center;'>".$desknm."</td>";
									}
									else if($desknm=='')
									{
										echo "<td style='text-align:center;'>डेस्क लावणे बाकी</td>";
									}
									echo "<td style='text-align:center;'>".$dis_date."</td>";*/
									if($test['ltr_status']=='')
									{
										echo "<td class='center'> कार्यवाही करणे बाकी </td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";		
									}
									echo "</tr>";
								}
							//mysql_close();
							echo "</table></center></div>";
							
		}					
?><br>
					<p>	
						<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
						<input type="button" class="btn" onclick="tableToExcel('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 Sandharbh Wise Report For Department User ###########################################

} //else if($flag=='n')
?>

