  <?php ############################################ Department Wise Sadyasthiti Report ##########################################

$username = $_SESSION['User_Name'];
$flag=$_REQUEST['flag'];
if($flag=='')
{
include_once('dashboard_department.php');
require_once('convert_marathi.php');
convert_marathi();
$qry=mysql_query("select dept_id,dept_nm from department_master where dept_id =(select dept_id from login where 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 src="tableToExcel.js"></script>   
<script type="text/javascript" src="js/adduser.js"></script> 
</head>
    <div class="rightpanel"> 
        <ul class="breadcrumbs">
            <li><a href="dashboard_department.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['dept_nm']; ?>ची कार्यविवरण नोंदवही / वर्कशिट</h4>
				<form name="sadyasthiti" action="sadyasthiti_department.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;
						
						$deptid=$rwq['dept_id'];
						
						?></font>
						</p>
						<br>			
						<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="head1 center">पत्राची स्थिती </th>
							<th class="head0 center">जावक_क्रमांक<br> व्यक्तीचे नाव </th>
							<th class="head1 center">View</th>
						</tr>
					</thead>
					<tbody>	
					<?php	
					if($date123==''&& $date223=='')
					{
						convert_marathi();			
						
						/////////dept accepted////////
						$qry=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.dept_id_to, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.dsk_id_to, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
						FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id
						LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
						where t.dept_id_from = '$deptid' AND t.returned_choice='' ") or die("".mysql_error());
						
						/////dept not accepted////////////
						$qry1=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.dept_id_to, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
						where i.dept_id = '$deptid'
						AND i.status='pending' ") or die("".mysql_error());
						
					}
					else 
					{
						convert_marathi();			
						$qry=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.dept_id_to, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, di.dsk_id_to, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id where t.dept_id_from = '$deptid' AND t.returned_choice=''
						AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
						
						$qry1=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.dept_id_to, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
						where i.dept_id = '$deptid'
						AND i.status='pending'
						AND (i.sent_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
					}
					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'];
						$dptinwrdno=$rws['dpt_inword_no'];
								########################### 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);
								}
								########################### Fetch desk name ##############################
								if($rws['desk_id_from']!='' || $rws['desk_id_from']!='0')
								{
									$dsk=$rws['desk_id_from'];
									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 ####################################
								if($rws['desk_id']=='0' || $rws['desk_id']=='')
								{
									echo "<td class='center'><font color='red'>डेस्क लावणे बाकी</font> </td>";
								}
								else if($rws['desk_ltr_inword_no']=='' || $rws['desk_ltr_inword_no']=='0')
								{
									echo "<td class='center'><font color='red'>डेस्कने स्वीकारणे बाकी</font> </td>";
								}
								else
								{
									echo "<td class='center'>".$desk['desk_nm']."<br>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1." </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 ##########################				
								$deptii=$rws['dept_id_from'];
								convert_marathi();
								$qdpti=mysql_query("Select dept_nm from department_master Where dept_id='$deptii'") or die("".mysql_error());
								$dept12=mysql_fetch_array($qdpti);
								
								$q=mysql_query("SELECT rtn_to_dsk from returned_from_desk where dpt_inword_no='$dptinwrdno'
								AND returned_from='$dsk' ");
								$r=mysql_fetch_array($q);
								
								if($r['rtn_to_dsk']!='')
								{	
									$dskid=$r['rtn_to_dsk'];
									$qski=mysql_query("Select desk_nm from desk_master Where desk_id='$dskid'") or die("".mysql_error());
									$desk=mysql_fetch_array($qski);
									$returnto=$desk['desk_nm'];
								}
								else
								{
									$returnto=$dept12['dept_nm'];
								}
								
								if($rws['ltr_status']=='' && $rws['waitflag']!='W')
								{
									echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['ltr_status']=='closed')
								{
									echo "<td class='center'> Letter Returned to <br>".$returnto." </td>";
								}
								else
								{
									echo "<td class='center'>".$rws['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								$dept_to=$rws['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);
								
								$todsk=$rws['dsk_id_to'];
								$qq=mysql_query("SELECT desk_nm from  desk_master where desk_id='$todsk' ");
								$rr=mysql_fetch_array($qq);
								if($rws['ltr_status']=='' && $rws['waitflag']=='W' && $rws['wait_kar_flag']=='N')
								{
									echo "<td class=center><font color='red'>"."Await Register"."</font></td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']=='W' && $rws['wait_kar_flag']=='A')
								{	
									echo "<td class=center>"."Await Register Complete"."</td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']=='' && $rws['wait_kar_flag']=='')
								{
									echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['ltr_approval']=='transferred')
								{
									echo "<td class=center>".$rws['ltr_approval']." to<br>".$depto['dept_nm']."</td>";
								}
								else if($rws['ltr_approval']=='transferred_todesk')
								{
									
									echo "<td class=center>transferred to<br>".$rr['desk_nm']."</td>";
								}
								else if($rws['ltr_approval']=='Approve')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								} 
								##############################################################################
								
								
								if($rws['waitflag']=='W' && $rws['wait_kar_flag']=='A')
								{
									echo "<td class='center'>"."कार्यवाही पूर्ण झाली."."</td>";
								}
								else if($rws['dispatched_to']=='' && $rws['ltr_status']!='updated' && $rws['ltr_status']!='closed')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								}
								else if($rws['ltr_status']=='updated')
								{
									echo "<td class='center'> अपडेट केले </td>";
								}
								else if($rws['dispatched_to']!='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws['dpt_inword_no']."<br>".$rws['addressed_to']."".$depto['dept_nm'].$rr['desk_nm']."</td>";
								}
								else if($rws['ltr_status']=='closed')
								{
									echo "<td class='center'>-- </td>";
								}
								############################# View #############################################
								
								echo" <td class='center'><a href='view_avak_javak.php?user=1&dptltrid=$dptltrid&dskltrid=$dskltrid'> View </a>";
								if($rws['ltr_approval']=='transferred' || $rws['ltr_approval']=='transferred_todesk')
								{
									echo "<br><a href='report_dpt_ltr_transfer_op.php?ltrid=$ltrid&user=dept'>DispatchDetails</a><br>";
								}
								
								echo "</td></tr>";
								
					}
					
					while($rws=mysql_fetch_array($qry1))
					{	
						$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);
								}
								########################### Fetch desk name ##############################
								if($rws['desk_id_from']!='' || $rws['desk_id_from']!='0')
								{
									$dsk=$rws['desk_id_from'];
									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'>डेस्क लावणे बाकी</font> </td>";
							
								############################## dpt######################################
								echo "<td class='center'><font color='red'> विभागाने स्वीकारणे बाकी </font> </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 #################################
								echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								
								##############################################################################
							
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								
								echo" <td class='center'> View ";
						
								echo "</td></tr>";
								
					}
					
					
					
					?>
                    </tbody>
					</table>
					<br>
					<?php
					echo "<div id='divToPrint' style='display:none;'>
							<table id='export' border='1px' style='margin-left:50px;'>";
							echo "<tr><td colspan='9'><center>". $rwq['dept_nm'] ."ची कार्यविवरण नोंदवही / वर्कशिट <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
						$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 '<center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
						$id = $date1;
						$id1= $date2;
						echo "</font>
						</p>
						<br>			
                        <tr>
                            <th>डेस्क आवक_क्र.<br>आवक_दिनांक</th>
                            <th>विभागीय आवक_क्र. <br>आवक_दिनांक</th>
							<th>पोलीस अधिक्षक <br> कार्यालय<br>आवक_क्र.<br>आवक_दिनांक</th>
                            <th>संदर्भ_क्र.<br>दिनांक</th>                          
                            <th>कोणाकडून प्राप्त झाला <br>विषय </th>                      
							<th> केलेली <br>कार्यवाही </th>
							<th>पत्राची स्थिती </th>
							<th>जावक_क्रमांक<br> व्यक्तीचे नाव </th>
						</tr>";	
					if($date123==''&& $date223=='')
					{
						convert_marathi();	
						
						//dept accepted
						$qry=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.dept_id_to, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,di.dsk_id_to, di.dispatched_to, de.ltr_category, de.assign_no 
						FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
						where t.dept_id_from = '$deptid' AND t.returned_choice='' ") or die("".mysql_error());
						
						//dept not accepted
						$qry1=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.dept_id_to, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
						where i.dept_id = '$deptid'
						AND i.status='pending' ") or die("".mysql_error());
					}
					else 
					{
						convert_marathi();			
						$qry=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.dept_id_to, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,di.dsk_id_to, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id where t.dept_id_from = '$deptid' AND t.returned_choice=''
						AND (t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
						
						$qry1=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.dept_id_to, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id 
						where i.dept_id = '$deptid'
						AND i.status='pending'
						AND (i.sent_dt BETWEEN '$date1' AND '$date2')") or die("".mysql_error());
					}
					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'];
						$dptinwrdno=$rws['dpt_inword_no'];
								########################### 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);
								}
								########################### Fetch desk name ##############################
								if($rws['desk_id_from']!='' || $rws['desk_id_from']!='0')
								{
									$dsk=$rws['desk_id_from'];
									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 ####################################
								if($rws['desk_id']=='0' || $rws['desk_id']=='')
								{
									echo "<td class='center'> डेस्क लावणे बाकी </td>";
								}
								else if($rws['desk_ltr_inword_no']=='' || $rws['desk_ltr_inword_no']=='0')
								{
									echo "<td class='center'>डेस्कने स्वीकारणे बाकी </td>";
								}
								else
								{
									echo "<td class='center'>".$desk['desk_nm']."<br>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1." </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 ##########################				
								$deptii=$rws['dept_id_from'];
								convert_marathi();
								$qdpti=mysql_query("Select dept_nm from department_master Where dept_id='$deptii'") or die("".mysql_error());
								$dept12=mysql_fetch_array($qdpti);
								
								$q=mysql_query("SELECT rtn_to_dsk from returned_from_desk where dpt_inword_no='$dptinwrdno'
								AND returned_from='$dsk' ");
								$r=mysql_fetch_array($q);
								
								if($r['rtn_to_dsk']!='')
								{	
									$dskid=$r['rtn_to_dsk'];
									$qski=mysql_query("Select desk_nm from desk_master Where desk_id='$dskid'") or die("".mysql_error());
									$desk=mysql_fetch_array($qski);
									$returnto=$desk['desk_nm'];
								}
								else
								{
									$returnto=$dept12['dept_nm'];
								}
								if($rws['ltr_status']=='' && $rws['waitflag']!='W')
								{
									echo "<td class=center>"."कार्यवाही करणे बाकी "."</td>";
								}
								else if($rws['ltr_status']=='closed')
								{
									echo "<td class='center'> Letter Returned to <br>".$returnto." </td>";
								}
								else
								{
									echo "<td class='center'>".$rws['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								$dept_to=$rws['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($rws['ltr_status']=='' && $rws['waitflag']=='W' && $rws['wait_kar_flag']=='N')
								{
									echo "<td class=center>"."Await Register"."</td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']=='W' && $rws['wait_kar_flag']=='A')
								{	
									echo "<td class=center>"."Await Register Complete"."</td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']=='' && $rws['wait_kar_flag']=='')
								{
									echo "<td class=center>"."कार्यवाही करणे बाकी "."</td>";
								}
								else if($rws['ltr_approval']=='transferred')
								{
									echo "<td class=center>".$rws['ltr_approval']." to<br>".$depto['dept_nm']."</td>";
								}
								else if($rws['ltr_approval']=='transferred_todesk')
								{
									$todsk=$rws['dsk_id_to'];
									$qq=mysql_query("SELECT desk_nm from  desk_master where desk_id='$todsk' ");
									$rr=mysql_fetch_array($qq);
									echo "<td class=center>transferred to<br>".$rr['desk_nm']."</td>";
								}
								else if($rws['ltr_approval']=='Approve')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								} 
								##############################################################################
								
								
								if($rws['waitflag']=='W' && $rws['wait_kar_flag']=='A')
								{
									echo "<td class='center'>"."कार्यवाही पूर्ण झाली."."</td>";
								}
								else if($rws['dispatched_to']=='' && $rws['ltr_status']!='updated' && $rws['ltr_status']!='closed')
								{
									echo "<td class='center'>"."कार्यवाही करणे बाकी"."</td>";
								}
								else if($rws['ltr_status']=='updated')
								{
									echo "<td class='center'> अपडेट केले</td>";
								}
								else if($rws['dispatched_to']!='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws['dpt_inword_no']."<br>".$rws['addressed_to']."".$depto['dept_nm']."</td>";
								}
								else if($rws['ltr_status']=='closed')
								{
									echo "<td class='center'>-- </td>";
								}
								############################# View #############################################
								
								echo "</tr>";
					}
					
					while($rws=mysql_fetch_array($qry1))
					{	
						$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);
								}
								########################### Fetch desk name ##############################
								if($rws['desk_id_from']!='' || $rws['desk_id_from']!='0')
								{
									$dsk=$rws['desk_id_from'];
									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'>डेस्क लावणे बाकी </td>";
							
								############################## dpt######################################
								echo "<td class='center'> विभागाने स्वीकारणे बाकी  </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 #################################
								echo "<td class=center>"."कार्यवाही करणे बाकी "."</td>";
								
								##############################################################################
							
									echo "<td class='center'>"."कार्यवाही करणे बाकी"."</td>";
								
								echo "</tr>";
								
					}
                    echo "</table></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>
<?php
} //if($flag=='')


else if($flag=='n')
{
require_once('convert_marathi.php');
include_once('new_dashboard_department.php');
$qry=mysql_query("select dept_id,dept_nm from department_master where dept_id =(select dept_id from login where 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 src="tableToExcel.js"></script>   
<script type="text/javascript" src="js/adduser.js"></script> 
</head>
    <div class="rightpanel"> 
        <ul class="breadcrumbs">
            <li><a href="new_dashboard_department.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['dept_nm']; ?>ची कार्यविवरण नोंदवही / वर्कशिट</h4>
				<form name="sadyasthiti" action="sadyasthiti_department.php?flag=n" 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
						$deptid=$rwq['dept_id'];
						
						$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>			
						<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="head1 center">पत्राची स्थिती </th>
							<th class="head0 center">जावक_क्रमांक<br> व्यक्तीचे नाव </th>
							<th class="head1 center">View</th>
						</tr>
					</thead>
					<tbody>	
					<?php	
					if($date123==''&& $date223=='')
					{
						convert_marathi();			
							
						//accepted by dept
						$qry=mysql_query("SELECT DISTINCT t.waitflag, t.wait_kar_flag,t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from as a,t.action_taken, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.dept_id_from, di.dept_id_to, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no ,di.desk_ltr_id
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON (di.ltr_id = t.ltr_id )
						where t.dept_id_from = '$deptid'
						AND t.returned_choice='' 
						ORDER BY t.dpt_ltr_id ASC") or die("aaaaaaaa".mysql_error());
						
						//not acceptd by dept
						$result1 = mysql_query("SELECT DISTINCT i.subject, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON (di.ltr_id = t.ltr_id )
						WHERE i.status='pending' 
						AND i.dept_id = (SELECT dept_id from login where login_id = '$username')") or die("cccc2".mysql_error());
						
					}
					else 
					{
						convert_marathi();			
						
						//accepted by dept
						$qry=mysql_query("SELECT DISTINCT t.waitflag, t.wait_kar_flag,t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc,di.dept_id_to, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no FROM 
						tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON (di.ltr_id = t.ltr_id )
						where t.dept_id_from = '$deptid' 
						AND t.returned_choice='' 
						AND t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2'
						ORDER BY t.dpt_ltr_id ASC ") or die("bbbbb".mysql_error());
						
						//not acceptd by dept
						$result1 = mysql_query("SELECT DISTINCT i.subject, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON (di.ltr_id = t.ltr_id )
						WHERE i.status='pending' 
						AND i.dept_id = (SELECT dept_id from login where login_id = '$username')") or die("cccc2".mysql_error());
					}
					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['a']!='' || $rws['a']!='0')
								{
									$depti=$rws['a'];
									convert_marathi();
									$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
								}
						/*		########################### Fetch desk name ##############################
								if($rws['desk_id_from']!='' || $rws['desk_id_from']!='0')
								{
									$dsk=$rws['desk_id_from'];
									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 ####################################
							/*	if($rws['desk_id']=='0' || $rws['desk_id']=='')
								{
									echo "<td class='center'><font color='red'>डेस्क लावणे बाकी</font> </td>";
								}
								else if($rws['desk_ltr_inword_no']=='' || $rws['desk_ltr_inword_no']=='0')
								{
									echo "<td class='center'><font color='red'>डेस्कने स्वीकारणे बाकी</font> </td>";
								}
								else
								{
									echo "<td class='center'>".$desk['desk_nm']."<br>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1." </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 ##########################				
								if($rws['action_taken']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']!='W')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else
								{
									echo "<td class='center'>".$rws['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								$todeptid=$rws['dept_id_to'];
								$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$todeptid'")or die("".mysql_error());
								$dept=mysql_fetch_array($qdpt);
									
								if($rws['ltr_status']=='' && $rws['waitflag']=='W' && $rws['wait_kar_flag']=='N')
								{
									echo "<td class=center><font color='red'>"."Await Register"."</font></td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']=='W' && $rws['wait_kar_flag']=='A')
								{	
									echo "<td class=center>"."Await Register Complete"."</td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']=='' && $rws['wait_kar_flag']=='')
								{
									echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['status']=='transferred')
								{
									echo "<td class=center>".$rws['status']." to<br>".$dept['dept_nm']."</td>";
								}
								else if($rws['status']=='dispatched')
								{
									echo "<td class=center>".$rws['status']."</td>";
								}
								else if($rws['ltr_status']=='updated')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								}
								##############################################################################
								/*if($rws['dispatched_to']=='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								}*/
								
								$dept_to=$rws['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($rws['waitflag']=='W' && $rws['wait_kar_flag']=='A')
								{
									echo "<td class='center'>"."कार्यवाही पूर्ण झाली."."</td>";
								}
								else if($rws['dispatched_to']=='' && $rws['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								}
								else if($rws['ltr_status']=='updated')
								{
								
									echo "<td class='center'> अपडेट केले </td>";
								}
								else if($rws['ltr_status']=='dispatched' && $rws['status']=='transferred' )
								{
								 //echo "<td class='center'>".$rws['outword_no']."<br> ".$rws['dept_nm']."ला <br> ट्रान्स्फर  केले</td>";
								 echo "<td class='center'>".$rws['dpt_inword_no']."<br>".$dept['dept_nm']."</td>";
								}
								/*else if($rws['dispatched_to']!='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws['outword_no']."<br>".$rws['addressed_to']."</td>";
								}*/
								else if($rws['dispatched_to']!='' && $rws['ltr_status']='dispatched' && $rws['status']='dispatched')
								{
									echo "<td class='center'>".$rws['dpt_inword_no']."<br>".$rws['addressed_to']."</td>";
								}
								################################################################################
								echo" <td class='center'><a href='view_avak_javak.php?flag=n&user=1&dptltrid=$dptltrid&dskltrid='a'> View </a>";
								
								if($rws['status']=='transferred')
								{
									echo "<br><a href='report_dpt_ltr_transfer_op.php?ltrid=$ltrid&user=deptn'>DispatchDetails</a><br>";
								}
								echo "</td></tr>";
								
					}
					
					while($rws1=mysql_fetch_array($result1))
					{	
						$ltrid=$rws1['ltr_id'];
						$dptltrid=$rws1['dpt_ltr_id'];
						########################### 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);
						}
						################# convert date in suitable format ##########################
								$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'>";
						############################## 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($rws1['action_taken']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws1['ltr_status']==''  && $rws1['waitflag']!='W')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else
								{
									echo "<td class='center'>".$rws1['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								if($rws1['ltr_status']=='')
								{
									echo "<td class=center><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws1['status']=='transferred')
								{
									echo "<td class=center>".$rws1['status']."</td>";
								}
								else if($rws1['status']=='dispatched')
								{
									echo "<td class=center>".$rws1['status']."</td>";
								}
								else if($rws1['ltr_status']=='updated')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								}
								##############################################################################
								/*if($rws['dispatched_to']=='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								}*/
								if($rws1['waitflag']=='W' && $rws1['wait_kar_flag']=='A')
								{
									echo "<td class='center'>"."कार्यवाही पूर्ण झाली."."</td>";
								}
								else if($rws1['dispatched_to']=='' && $rws1['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								}
								else if($rws1['ltr_status']=='updated')
								{
								
									echo "<td class='center'> अपडेट केले </td>";
								}
								else if($rws1['ltr_status']=='dispatched' && $rws1['status']=='transferred' )
								{
								 //echo "<td class='center'>".$rws['outword_no']."<br> ".$rws['dept_nm']."ला <br> ट्रान्स्फर  केले</td>";
								 echo "<td class='center'>".$rws1['dpt_inword_no']."</td>";
								}
								/*else if($rws['dispatched_to']!='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws['outword_no']."<br>".$rws['addressed_to']."</td>";
								}*/
								else if($rws1['dispatched_to']!='' && $rws1['ltr_status']='dispatched' && $rws1['status']='dispatched')
								{
									echo "<td class='center'>".$rws1['dpt_inword_no']."<br>".$rws1['addressed_to']."</td>";
								}
								################################################################################
								echo" <td class='center'> View ";
						
								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['dept_nm'] ."ची कार्यविवरण नोंदवही / वर्कशिट <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
						echo '<center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
						
						$date123	= $_POST['start_date'];
						$date1	= date('Y-m-d',strtotime($date123));
						$date223	= $_POST['end_date'];
						$date2	= date('Y-m-d',strtotime($date223));
						//$date22	= date('d-m-Y',strtotime($date2));
						
						$id = $date1;
						$id1= $date2;
						/*echo "</font>
						</p>
						<br>			
                        <tr>
							<th>आवक_क्रमांक <br>आवक दिनांक</th>
							<th>विभागीय आवक_क्रमांक <br>दिनांक</th>
							<th>डेस्क आवक_क्रमांक <br>आवक दि. </th>
							<th>संदर्भ_क्रमांक <br>संदर्भ दि. </th>
							<th>विषय</th>
							<th>कोणाकडून प्राप्त झाला</th>
							<th>डेस्कचे नाव </th>
							<th>केलेली <br>कार्यवाही</th>	
                        </tr>";	*/
						echo "</font>
						</p>
						<br>			
                        <tr>
							 <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='head1 center'>पत्राची स्थिती </th>
							<th class='head0 center'>जावक_क्रमांक<br> व्यक्तीचे नाव </th>
							
                        </tr>";
						if($date123==''&& $date223=='')
					{
						convert_marathi();	
						
						//accepted by dept
						$qry=mysql_query("SELECT DISTINCT t.waitflag, t.wait_kar_flag,t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc,di.dept_id_to, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON (di.ltr_id = t.ltr_id )
						where t.dept_id_from = '$deptid'
						AND t.returned_choice='' ") or die("aaaaaaaa".mysql_error());
					
						//not acceptd by dept
						$result1 = mysql_query("SELECT DISTINCT i.subject, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON (di.ltr_id = t.ltr_id )
						WHERE i.status='pending' 
						AND i.dept_id = (SELECT dept_id from login where login_id = '$username')") or die("cccc2".mysql_error());
						
					}
					else 
					{
						convert_marathi();			
						
						//accepted by dept
						$qry=mysql_query("SELECT DISTINCT t.waitflag, t.wait_kar_flag,t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.dept_id_from,t.action_taken, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc,di.dept_id_to, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no FROM 
						tapal_to_dpt_transaction t LEFT OUTER JOIN incoming_letters_transaction  i ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON (di.ltr_id = t.ltr_id )
						where t.dept_id_from = '$deptid' AND t.returned_choice='' AND t.dpt_ltr_rec_dt BETWEEN '$date1' AND '$date2' ") or die("bbbbb".mysql_error());
						
						//not acceptd by dept
						$result1 = mysql_query("SELECT DISTINCT i.subject, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON (di.ltr_id = t.ltr_id )
						WHERE i.status='pending' 
						AND i.dept_id = (SELECT dept_id from login where login_id = '$username')") or die("cccc2".mysql_error());
					}
					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);
								}
						/*		########################### Fetch desk name ##############################
								if($rws['desk_id_from']!='' || $rws['desk_id_from']!='0')
								{
									$dsk=$rws['desk_id_from'];
									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'>";
							############################## 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 ##########################				
								if($rws['action_taken']=='')
								{
									echo "<td class='center'> कार्यवाही करणे बाकी  </td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']!='W')
								{
									echo "<td class='center'> कार्यवाही करणे बाकी </td>";
								}
								else
								{
									echo "<td class='center'>".$rws['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								$todeptid=$rws['dept_id_to'];
								$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$todeptid'")or die("".mysql_error());
								$dept=mysql_fetch_array($qdpt);
								if($rws['ltr_status']=='' && $rws['waitflag']=='W' && $rws['wait_kar_flag']=='N')
								{
									echo "<td class=center>"."Await Register"."</td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']=='W' && $rws['wait_kar_flag']=='A')
								{	
									echo "<td class=center>"."Await Register Complete"."</td>";
								}
								else if($rws['ltr_status']=='' && $rws['waitflag']=='' && $rws['wait_kar_flag']=='')
								{
									echo "<td class=center> कार्यवाही करणे बाकी </td>";
								}
								else if($rws['status']=='transferred')
								{
									
									echo "<td class=center>".$rws['status']." to<br>".$dept['dept_nm']."</td>";
								}
								else if($rws['status']=='dispatched')
								{
									echo "<td class=center>".$rws['status']."</td>";
								}
								else if($rws['ltr_status']=='updated')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								}
								##############################################################################
								/*if($rws['dispatched_to']=='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								}*/
								if($rws['waitflag']=='W' && $rws['wait_kar_flag']=='A')
								{
									echo "<td class='center'>"."कार्यवाही पूर्ण झाली."."</td>";
								}
								else if($rws['dispatched_to']=='' && $rws['ltr_status']=='')
								{
									echo "<td class='center'> कार्यवाही करणे बाकी </td>";
								}
								else if($rws['ltr_status']=='updated')
								{
								
									echo "<td class='center'> अपडेट केले </td>";
								}
								else if($rws['ltr_status']=='dispatched' && $rws['status']=='transferred' )
								{
								 //echo "<td class='center'>".$rws['outword_no']."<br> ".$rws['dept_nm']."ला <br> ट्रान्स्फर  केले</td>";
								 echo "<td class='center'>".$rws['dpt_inword_no']."<br>".$dept['dept_nm']."</td>";
								}
								/*else if($rws['dispatched_to']!='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws['outword_no']."<br>".$rws['addressed_to']."</td>";
								}*/
								else if($rws['dispatched_to']!='' && $rws['ltr_status']='dispatched' && $rws['status']='dispatched')
								{
									echo "<td class='center'>".$rws['dpt_inword_no']."<br>".$rws['addressed_to']."</td>";
								}
								################################################################################
								
						
								echo "</tr>";
								
					}
					
					while($rws1=mysql_fetch_array($result1))
					{	
						$ltrid=$rws1['ltr_id'];
						$dptltrid=$rws1['dpt_ltr_id'];
						########################### 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);
						}
						################# convert date in suitable format ##########################
								$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'>";
						############################## 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($rws1['action_taken']=='')
								{
									echo "<td class='center'>कार्यवाही करणे बाकी</td>";
								}
								else if($rws1['ltr_status']=='' && $rws1['waitflag']!='W')
								{
									echo "<td class='center'>कार्यवाही करणे बाकी </td>";
								}
								else
								{
									echo "<td class='center'>".$rws1['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								if($rws1['ltr_status']=='')
								{
									echo "<td class=center>कार्यवाही करणे बाकी </td>";
								}
								else if($rws1['status']=='transferred')
								{
									echo "<td class=center>".$rws1['status']."</td>";
								}
								else if($rws1['status']=='dispatched')
								{
									echo "<td class=center>".$rws1['status']."</td>";
								}
								else if($rws1['ltr_status']=='updated')
								{
									echo "<td class=center>".$rws['ltr_status']."</td>";
								}
								##############################################################################
								/*if($rws['dispatched_to']=='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी"."</font></td>";
								}*/
								if($rws1['waitflag']=='W' && $rws1['wait_kar_flag']=='A')
								{
									echo "<td class='center'>"."कार्यवाही पूर्ण झाली."."</td>";
								}
								else if($rws1['dispatched_to']=='' && $rws1['ltr_status']=='')
								{
									echo "<td class='center'>कार्यवाही करणे बाकी</td>";
								}
								else if($rws1['ltr_status']=='updated')
								{
								
									echo "<td class='center'> अपडेट केले </td>";
								}
								else if($rws1['ltr_status']=='dispatched' && $rws1['status']=='transferred' )
								{
								 //echo "<td class='center'>".$rws['outword_no']."<br> ".$rws['dept_nm']."ला <br> ट्रान्स्फर  केले</td>";
								 echo "<td class='center'>".$rws1['dpt_inword_no']."</td>";
								}
								/*else if($rws['dispatched_to']!='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws['outword_no']."<br>".$rws['addressed_to']."</td>";
								}*/
								else if($rws1['dispatched_to']!='' && $rws1['ltr_status']='dispatched' && $rws1['status']='dispatched')
								{
									echo "<td class='center'>".$rws1['dpt_inword_no']."<br>".$rws1['addressed_to']."</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>
<?php
} //else if($flag=='n')
?>
