 <?php ######################################### Desk Wise Sadyasthiti Report ######################################
include_once('dashboard_desk.php');
require_once('convert_marathi.php');
$username = $_SESSION['User_Name'];
$qry=mysql_query("SELECT dm.desk_id, dm.desk_nm
FROM desk_master dm, login
WHERE login.desk_id = dm.desk_id
AND login_id = '$username'");
$rwq=mysql_fetch_array($qry);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tapal Admin System</title>
<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 type="text/javascript" src="js/adduser.js"></script> 
<script src="tableToExcel.js"></script>
</head>
    <div class="rightpanel"> 
        <ul class="breadcrumbs">
            <li><a href="dashboard_desk.php"><i class="iconfa-home"></i></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>
                <h1>कार्यविवरण नोंदवही / वर्कशिट </h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
			<h4 class="widgettitle"><?php echo $rwq['desk_nm']; ?>ची कार्यविवरण नोंदवही / वर्कशिट</h4>	
			<!-- Code For Start Date End Date Input -->
				<form name="sadyasthiti" action="sadhyasthiti_desk.php" method="post">
					<div align="center"><br><table align="center" cellpadding="2" cellspacing="0" class='myClass'>
						<table>
							<tr>
								<td align="center"><label style="width:110px;">Start date</label></td>
								<td align="center"><input type="text" name="start_date" class="input-small"/></td>
								<td align="center"><label style="width:110px;">End Date</label></td>
								<td align="center"><input type="text" name="end_date" class="input-small"/></td>
							</tr>
							<tr>
								<td colspan="4">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDate()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
				</form>
			           
						<p align="center"><font size="4" color='#0866c6' style="font-family:verdana;"><br>
						<?php
						$date123	= $_POST['start_date'];
						$date1	= date('Y-m-d',strtotime($date123));
						$date223	= $_POST['end_date'];
						$date2	= date('Y-m-d',strtotime($date223));
						//$date22	= date('d-m-Y',strtotime($date2));
						echo 'दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font>';$id = $date1;
						$id1= $date2;
						?></font>
						</p>
						<br>			
						
							<?php	
							convert_marathi();
							$deskid=$rwq['desk_id'];
							
							if($date123==''&& $date223=='')
							{
								convert_marathi();			
								
								//////not accepted by desk///////////
								$qry=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.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.dept_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								where t.desk_id = '$deskid' 
								AND t.desk_approval='pending' ") or die("".mysql_error());
																
								///////////accepted by desk///////////
								$qry1=mysql_query("SELECT de.waitflag,de.wait_kar_flag,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.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.dept_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								where de.desk_id_from = '$deskid' ") or die("".mysql_error());
								
							}
							else 
							{
								convert_marathi();			
								
								//////not accepted by desk///////////
								$qry=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.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.dept_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								where t.desk_id = '$deskid' 
								AND t.desk_approval='pending'
								AND (t.sent_to_desk_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
								
								///////////accepted by desk///////////
								$qry1=mysql_query("SELECT de.waitflag,de.wait_kar_flag,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.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.dept_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								where de.desk_id_from = '$deskid' 
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
							}
							
							?>
								<table id="dyntable" class="table table-bordered">
							<thead>
								<tr>	
									<th class="head0 center">डेस्क आवक_क्र.<br>आवक_दिनांक</th>
									<th class="head1 center">विभागीय आवक_क्र. <br>आवक_दिनांक</th>
									<th class="head0 center">पोलीस अधिक्षक <br> कार्यालय<br>आवक_क्र.<br>आवक_दिनांक</th>
									<th class="head1 center">संदर्भ_क्र.<br>प्राप्त_दिनांक</th>                          
									<th class="head0 center">कोणाकडून प्राप्त झाला <br>विषय </th>                      
									<th class="head0 center"> केलेली <br>कार्यवाही </th>
									<th class="head0 center">जावक_क्रमांक<br> व्यक्तीचे नाव </th>
									<th class="head1 center">View</th>
								</tr>
							</thead>
							<tbody>
					<?php		
					while($rws=mysql_fetch_array($qry))
					{	
						$deskltrid=$rws['desk_ltr_id'];
						$ltrid=$rws['ltr_id'];
						$dptltrid=$rws['dpt_ltr_id'];
						$dskltrid=$rws['desk_ltr_id'];
						
								########################### Fetch department name ##############################
								if($rws['dept_id_from']!='' || $rws['dept_id_from']!='0')
								{
									$depti=$rws['dept_id_from'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									//echo $dept['dept_nm']."aaa";
								}
								########################### Fetch desk name ##############################
								if($rws['desk_id']!='' || $rws['desk_id']!='0')
								{
									$dsk=$rws['desk_id'];
									//echo $dsk."aaaaaaaaa";
									convert_marathi();
									$qsk=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk'") or die("".mysql_error());
									$desk=mysql_fetch_array($qsk);
								}
								################# convert date in suitable format ##########################
								$dsrecdt = strtotime($rws['desk_ltr_rec_dt']);
								$dsrecdt1= date('d-m-Y', $dsrecdt);
								$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
								$dprecdt1= date('d-m-Y', $dprecdt);
								
								$refdt = strtotime($rws['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rws['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);		
								echo "<tr class='gradeX'>";
								################################### Desk ####################################
								
									echo "<td class='center'><font color='red'>".$desk['desk_nm']."<br> डेस्कने स्वीकारणे बाकी </font> </td>";
								
							
								############################## dpt######################################
								if($rws['dept_id']=='0' || $rws['dept_id']=='')
								{
									echo "<td class='center'><font color='red'>विभाग लावणे बाकी</font> </td>";
								}
								else if($rws['dpt_inword_no']=='' || $rws['dpt_inword_no']=='0')
								{
									echo "<td class='center'><font color='red'> विभागाने स्वीकारणे बाकी </font> </td>";
								}
								else
								{
									echo "<td class='center'>".$dept['dept_nm']."<br>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
								}
								################################### common things #######################
								echo "<td class='center'>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
								<td class='center'>".$rws['ref_no']."<br>".$refdt1."</td>
								<td><b>नाव : </b>".$rws['sender_name']."<br><b>विषय : </b>".$rws['subject']."</td>";
								################## If Action Taken Pending ##########################				
								
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								
								######################### For Letter Status #################################
								/*if($rws['action_taken']=='')
								{
									echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['action_taken']!='' && $rws['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['ltr_approval']=='transferred')
								{
									echo "<td class=center>".$rws['ltr_approval']."</td>";
								}
								else if($rws['ltr_approval']=='Approve')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								}*/
								
								##############################################################################
								
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								
								############################ VIew ##############################################
								if($rws['desk_ltr_inword_no']=='' || $rws['dpt_inword_no']=='0')
								{
									echo "<td class='center'> View </td>";
								}
								else
								{
									echo" <td class='center'><a href='view_avak_javak.php?user=2&dskltrid=$dskltrid'> View </a>";
								}
								echo "</td></tr>";
					}
					
					while($rws1=mysql_fetch_array($qry1))
					{	
						$deskltrid=$rws1['desk_ltr_id'];
						$ltrid=$rws1['ltr_id'];
						$dptltrid=$rws1['dpt_ltr_id'];
						$dskltrid=$rws1['desk_ltr_id'];
						
						//closed lettr
						$ltrinward=$rws1['ltr_inword_no'];
						$deskidfrom=$rws1['desk_id_from'];
						if($rws1['ltr_status']=='closed')
						{
							$query=mysql_query("select rtn_to_dsk from  returned_from_desk 
												where ltr_inword_no='$ltrinward'
												AND returned_from='$deskidfrom' ");
							$result=mysql_fetch_array($query);
							//echo $result['rtn_to_dsk']."<br>";
						}
								########################### Fetch department name ##############################
								if($rws1['dept_id_from']!='' || $rws1['dept_id_from']!='0')
								{
									$depti=$rws1['dept_id_from'];
									convert_marathi();
									$qdpt1=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept1=mysql_fetch_array($qdpt1);
									//echo $dept1['dept_nm']."aaa";
								}
								########################### Fetch desk name ##############################
								if($rws1['desk_id_from']!='' || $rws1['desk_id_from']!='0')
								{
									$dsk1=$rws1['desk_id_from'];
									//echo $dsk."aaaaaaaaa";
									convert_marathi();
									$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
									$desk1=mysql_fetch_array($qsk1);
								}
								################# convert date in suitable format ##########################
								$dsrecdt = strtotime($rws1['desk_ltr_rec_dt']);
								$dsrecdt1= date('d-m-Y', $dsrecdt);
								$dprecdt = strtotime($rws1['dpt_ltr_rec_dt']);
								$dprecdt1= date('d-m-Y', $dprecdt);
								
								$refdt = strtotime($rws1['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rws1['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);		
								echo "<tr class='gradeX'>";
								################################### Desk ####################################
								if($rws1['desk_id']=='0' || $rws1['desk_id']=='')
								{
									echo "<td class='center'><font color='red'>डेस्क लावणे बाकी</font> </td>";
								}
								else if($rws1['desk_ltr_inword_no']=='' || $rws1['desk_ltr_inword_no']=='0')
								{
									echo "<td class='center'><font color='red'>डेस्कने स्वीकारणे बाकी </font> </td>";
								}
								else
								{
									echo "<td class='center'>".$desk1['desk_nm']."<br>".$rws1['desk_ltr_inword_no']."<br>".$dsrecdt1." </td>";
								}
							
								############################## dpt######################################
								if($rws1['dept_id']=='0' || $rws1['dept_id']=='')
								{
									echo "<td class='center'><font color='red'>विभाग लावणे बाकी</font> </td>";
								}
								else if($rws1['dpt_inword_no']=='' || $rws1['dpt_inword_no']=='0')
								{
									echo "<td class='center'><font color='red'> विभागाने स्वीकारणे बाकी </font> </td>";
								}
								else
								{
									echo "<td class='center'>".$dept1['dept_nm']."<br>".$rws1['dpt_inword_no']."<br>".$dprecdt1." </td>";
								}
								################################### common things #######################
								echo "<td class='center'>".$rws1['ltr_inword_no']."<br>".$recdt1." </td>
								<td class='center'>".$rws1['ref_no']."<br>".$refdt1."</td>
								<td><b>नाव : </b>".$rws1['sender_name']."<br><b>विषय : </b>".$rws1['subject']."</td>";
								################## If Action Taken Pending ##########################				
								if($result['rtn_to_dsk']=='')
								{
									$returnto=$dept1['dept_nm'];
									
								}
								else
								{
									$dsk_nm=$result['rtn_to_dsk'];
									$qw=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk_nm'") or die("".mysql_error());
									$de=mysql_fetch_array($qw);
									$returnto=$de['desk_nm'];
								}
								
								if($rws1['ltr_status']=='' && $rws1['waitflag']=='W' && $rws1['wait_kar_flag']=='N')
								{
									echo "<td class=center><font color='red'>"."Await Register"."</font></td>";
								}
								else if($rws1['ltr_status']=='' && $rws1['waitflag']=='W' && $rws1['wait_kar_flag']=='A')
								{	
									echo "<td class=center>"."Await Register Complete"."</td>";
								}
								else if($rws1['ltr_status']=='' && $rws1['waitflag']=='' && $rws1['wait_kar_flag']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws1['ltr_status']=='closed')
								{
									echo "<td class='center'> Letter Returned To <br>".$returnto."</td>";
								}
								else
								{
									echo "<td class='center'>".$rws1['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								/*if($rws['action_taken']=='')
								{
									echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['action_taken']!='' && $rws['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['ltr_approval']=='transferred')
								{
									echo "<td class=center>".$rws['ltr_approval']."</td>";
								}
								else if($rws['ltr_approval']=='Approve')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								}*/
								
								##############################################################################
								$dept_to=$rws1['dept_id_to'];
								$qdpto=mysql_query("Select dept_nm from department_master Where dept_id='$dept_to'") or die("".mysql_error());
								$depto=mysql_fetch_array($qdpto);
						
								if($rws1['waitflag']=='W' && $rws1['wait_kar_flag']=='A')
								{
									echo "<td class='center'>"."कार्यवाही पूर्ण झाली."."</td>";
								}
								else if($rws1['dispatched_to']=='' && $rws1['ltr_status']!='updated' && $rws1['ltr_status']!='closed')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								}
								else if($rws1['ltr_status']=='updated')
								{
									echo "<td class='center'> अपडेट केले </td>";
								}
								else if($rws1['dispatched_to']!='' && $rws1['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws1['dpt_inword_no']."<br>".$rws1['addressed_to']."".$depto['dept_nm']."</td>";
								}
								else if($rws1['ltr_status']=='closed')
								{
									echo "<td class='center'>-- </td>";
								}
								############################ VIew ##############################################
								if($rws1['desk_ltr_inword_no']=='' || $rws1['dpt_inword_no']=='0')
								{
									echo "<td class='center'> View </td>";
								}
								else
								{
									echo" <td class='center'><a href='view_avak_javak.php?user=2&dskltrid=$dskltrid'> View </a>";
									
									if($rws1['ltr_approval']=='transferred' || $rws1['ltr_approval']=='transferred_todesk')
									{
										echo "<br><a href='report_dpt_ltr_transfer_op.php?ltrid=$ltrid&user=desk'>DispatchDetails</a><br>";
									}
								}
								echo "</td></tr>";
					}
					?>
							</tbody>
						</table><br>
						
						<?php	
						echo "<div id='divToPrint' style='display:none;'>
							<center><table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='9'><center>". $rwq['desk_nm'] ." ची कार्यविवरण नोंदवही / वर्कशिट <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
						
						echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
						if($date123==''&& $date223=='')
							{
								convert_marathi();			
								//////not accepted by desk///////////
								$qry=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.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.dept_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								where t.desk_id = '$deskid' 
								AND t.desk_approval='pending' ") or die("".mysql_error());
								
								///////////accepted by desk///////////
								$qry1=mysql_query("SELECT de.waitflag,de.wait_kar_flag,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.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.dept_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								where de.desk_id_from = '$deskid' ") or die("".mysql_error());
								
							}
							else 
							{
								convert_marathi();			
								//////not accepted by desk///////////
								$qry=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.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.dept_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								where t.desk_id = '$deskid' 
								AND t.desk_approval='pending'
								AND (t.sent_to_desk_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
								
								///////////accepted by desk///////////
								$qry1=mysql_query("SELECT de.waitflag,de.wait_kar_flag,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.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.dept_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
								FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
								LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id 
								LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
								where de.desk_id_from = '$deskid' 
								AND (de.desk_ltr_rec_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
							}
						$id = $date1;
					
						echo "
								<tr>	
									<th>डेस्क आवक_क्र.<br>आवक_दिनांक</th>
									<th>विभागीय आवक_क्र. <br>आवक_दिनांक</th>
									<th>पोलीस अधिक्षक <br> कार्यालय<br>आवक_क्र.<br>आवक_दिनांक</th>
									<th>संदर्भ_क्र.<br>प्राप्त_दिनांक</th>                          
									<th>कोणाकडून प्राप्त झाला <br>विषय </th>                      
									<th> केलेली <br>कार्यवाही </th>
									<th>जावक_क्रमांक<br> व्यक्तीचे नाव </th>
								</tr>";
					while($rws=mysql_fetch_array($qry))
					{	
						$deskltrid=$rws['desk_ltr_id'];
						$ltrid=$rws['ltr_id'];
						$dptltrid=$rws['dpt_ltr_id'];
						$dskltrid=$rws['desk_ltr_id'];
						
								########################### Fetch department name ##############################
								if($rws['dept_id_from']!='' || $rws['dept_id_from']!='0')
								{
									$depti=$rws['dept_id_from'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
									//echo $dept['dept_nm']."aaa";
								}
								########################### Fetch desk name ##############################
								if($rws['desk_id']!='' || $rws['desk_id']!='0')
								{
									$dsk=$rws['desk_id'];
									//echo $dsk."aaaaaaaaa";
									convert_marathi();
									$qsk=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk'") or die("".mysql_error());
									$desk=mysql_fetch_array($qsk);
								}
								################# convert date in suitable format ##########################
								$dsrecdt = strtotime($rws['desk_ltr_rec_dt']);
								$dsrecdt1= date('d-m-Y', $dsrecdt);
								$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
								$dprecdt1= date('d-m-Y', $dprecdt);
								
								$refdt = strtotime($rws['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rws['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);		
								echo "<tr class='gradeX'>";
								################################### Desk ####################################
								
									echo "<td class='center'>".$desk['desk_nm']."<br> डेस्कने स्वीकारणे बाकी  </td>";
								############################## dpt######################################
								if($rws['dept_id']=='0' || $rws['dept_id']=='')
								{
									echo "<td class='center'> विभाग लावणे बाकी </td>";
								}
								else if($rws['dpt_inword_no']=='' || $rws['dpt_inword_no']=='0')
								{
									echo "<td class='center'> विभागाने स्वीकारणे बाकी  </td>";
								}
								else
								{
									echo "<td class='center'>".$dept['dept_nm']."<br>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
								}
								################################### common things #######################
								echo "<td class='center'>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
								<td class='center'>".$rws['ref_no']."<br>".$refdt1."</td>
								<td><b>नाव : </b>".$rws['sender_name']."<br><b>विषय : </b>".$rws['subject']."</td>";
								################## If Action Taken Pending ##########################				
								
									echo "<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
								
								######################### For Letter Status #################################
								/*if($rws['action_taken']=='')
								{
									echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['action_taken']!='' && $rws['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['ltr_approval']=='transferred')
								{
									echo "<td class=center>".$rws['ltr_approval']."</td>";
								}
								else if($rws['ltr_approval']=='Approve')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								}*/
								
								##############################################################################
								
									echo "<td class='center'>"."कार्यवाही करणे बाकी"."</td>";
								
							
								echo "</tr>";
					}
					
					while($rws1=mysql_fetch_array($qry1))
					{	
						$deskltrid=$rws1['desk_ltr_id'];
						$ltrid=$rws1['ltr_id'];
						$dptltrid=$rws1['dpt_ltr_id'];
						$dskltrid=$rws1['desk_ltr_id'];
						
						$ltrinward=$rws1['ltr_inword_no'];
						$deskidfrom=$rws1['desk_id_from'];
						if($rws1['ltr_status']=='closed')
						{
							$query=mysql_query("select rtn_to_dsk from  returned_from_desk 
												where ltr_inword_no='$ltrinward'
												AND returned_from='$deskidfrom' ");
							$result=mysql_fetch_array($query);
							//echo $result['rtn_to_dsk']."<br>";
						}
								########################### Fetch department name ##############################
								if($rws1['dept_id_from']!='' || $rws1['dept_id_from']!='0')
								{
									$depti=$rws1['dept_id_from'];
									convert_marathi();
									$qdpt1=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept1=mysql_fetch_array($qdpt1);
									//echo $dept1['dept_nm']."aaa";
								}
								########################### Fetch desk name ##############################
								if($rws1['desk_id_from']!='' || $rws1['desk_id_from']!='0')
								{
									$dsk1=$rws1['desk_id_from'];
									//echo $dsk."aaaaaaaaa";
									convert_marathi();
									$qsk1=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk1'") or die("".mysql_error());
									$desk1=mysql_fetch_array($qsk1);
								}
								################# convert date in suitable format ##########################
								$dsrecdt = strtotime($rws1['desk_ltr_rec_dt']);
								$dsrecdt1= date('d-m-Y', $dsrecdt);
								$dprecdt = strtotime($rws1['dpt_ltr_rec_dt']);
								$dprecdt1= date('d-m-Y', $dprecdt);
								
								$refdt = strtotime($rws1['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rws1['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);		
								echo "<tr class='gradeX'>";
								################################### Desk ####################################
								if($rws1['desk_id']=='0' || $rws1['desk_id']=='')
								{
									echo "<td class='center'>डेस्क लावणे बाकी </td>";
								}
								else if($rws1['desk_ltr_inword_no']=='' || $rws1['desk_ltr_inword_no']=='0')
								{
									echo "<td class='center'>डेस्कने स्वीकारणे बाकी  </td>";
								}
								else
								{
									echo "<td class='center'>".$desk1['desk_nm']."<br>".$rws1['desk_ltr_inword_no']."<br>".$dsrecdt1." </td>";
								}
							
								############################## dpt######################################
								if($rws1['dept_id']=='0' || $rws1['dept_id']=='')
								{
									echo "<td class='center'>विभाग लावणे बाकी </td>";
								}
								else if($rws1['dpt_inword_no']=='' || $rws1['dpt_inword_no']=='0')
								{
									echo "<td class='center'> विभागाने स्वीकारणे बाकी  </td>";
								}
								else
								{
									echo "<td class='center'>".$dept1['dept_nm']."<br>".$rws1['dpt_inword_no']."<br>".$dprecdt1." </td>";
								}
								################################### common things #######################
								echo "<td class='center'>".$rws1['ltr_inword_no']."<br>".$recdt1." </td>
								<td class='center'>".$rws1['ref_no']."<br>".$refdt1."</td>
								<td><b>नाव : </b>".$rws1['sender_name']."<br><b>विषय : </b>".$rws1['subject']."</td>";
								################## If Action Taken Pending ##########################				
								if($result['rtn_to_dsk']=='')
								{
									$returnto=$dept1['dept_nm'];
									
								}
								else
								{
									$dsk_nm=$result['rtn_to_dsk'];
									$qw=mysql_query("Select desk_nm from desk_master Where desk_id='$dsk_nm'") or die("".mysql_error());
									$de=mysql_fetch_array($qw);
									$returnto=$de['desk_nm'];
								}
								
								if($rws1['ltr_status']=='' && $rws1['waitflag']=='W' && $rws1['wait_kar_flag']=='N')
								{
									echo "<td class=center>"."Await Register"."</td>";
								}
								else if($rws1['ltr_status']=='' && $rws1['waitflag']=='W' && $rws1['wait_kar_flag']=='A')
								{	
									echo "<td class=center>"."Await Register Complete"."</td>";
								}
								else if($rws1['ltr_status']=='' && $rws1['waitflag']=='' && $rws1['wait_kar_flag']=='')
								{
									echo "<td class='center'>"."कार्यवाही करणे बाकी "."</td>";
								}
								else if($rws1['ltr_status']=='closed')
								{
									echo "<td class='center'> Letter Returned To <br>".$returnto."</td>";
								}
								else
								{
									echo "<td class='center'>".$rws1['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								/*if($rws['action_taken']=='')
								{
									echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['action_taken']!='' && $rws['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['ltr_approval']=='transferred')
								{
									echo "<td class=center>".$rws['ltr_approval']."</td>";
								}
								else if($rws['ltr_approval']=='Approve')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								}*/
								
								##############################################################################
								$dept_to=$rws1['dept_id_to'];
								$qdpto=mysql_query("Select dept_nm from department_master Where dept_id='$dept_to'") or die("".mysql_error());
								$depto=mysql_fetch_array($qdpto);
						
								if($rws1['waitflag']=='W' && $rws1['wait_kar_flag']=='A')
								{
									echo "<td class='center'>"."कार्यवाही पूर्ण झाली."."</td>";
								}
								else if($rws1['dispatched_to']=='' && $rws1['ltr_status']!='updated' && $rws1['ltr_status']!='closed')
								{
									echo "<td class='center'>"."कार्यवाही करणे बाकी"."</td>";
								}
								else if($rws1['ltr_status']=='updated')
								{
									echo "<td class='center'> अपडेट केले </td>";
								}
								else if($rws1['dispatched_to']!='' && $rws1['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws1['dpt_inword_no']."<br>".$rws1['addressed_to']."".$depto['dept_nm']."</td>";
								}
								else if($rws1['ltr_status']=='closed')
								{
									echo "<td class='center'>-- </td>";
								}
								
								echo "</tr>";
					}
					echo"</table></center></div>";
								?>
						<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>
					  <br /><br />
					<?php include_once('footer.php'); ?>
					</div><!--maincontentinner-->
				</div><!--maincontent-->
			</div><!--rightpanel-->
		</div><!--mainwrapper-->
</body>
</html>