<?php
  session_start();
$username = $_SESSION['User_Name'];

include_once('dashboard_desk.php');
require_once('convert_marathi.php');
 
$sender_name= $_REQUEST['sender_name']; 
$mobile_no= $_REQUEST['mobile_no']; 
################################## Displaying Approved Letters InData Table To Perform Action #################################

?>
<!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>

</head>
<body>
	<div class="rightpanel">
		<ul class="breadcrumbs">
            <li><a href="dashboard_desk.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="dashboard_desk.php">Tables</a> <span class="separator"></span></li>
            <li> वारंवार येणारे पत्र  </li>
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
                <h5>Tables</h5>
                <h1> वारंवार येणारे पत्र  </h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
				<h4 class="widgettitle"> वारंवार येणारे पत्र  </h4>  
					
					<?php	
						
						convert_marathi();
						$result222=mysql_query("SELECT i.ltr_inword_no, i.receive_dt, i.ref_no, i.ref_dt, t.dpt_inword_no, t.dpt_ltr_rec_dt, d.desk_ltr_inword_no, d.desk_ltr_rec_dt, i.sender_name, i.subject, d.ltr_approval, d.ltr_status, d.action_taken, d.update_date, d.dispatched_dt, t.dept_id_from, t.sent_to_desk_dt, t.assign_dpt, t.desk_approval, di.dept_id_to, di.dsk_id_to
						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 d ON d.dpt_ltr_id = t.dpt_ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = d.desk_ltr_id 
						where d.desk_id_from=(select desk_id from login where login_id='$username') 
						AND i.sender_name='$sender_name'
						AND i.mobile_no='$mobile_no' ") or die("sdfdfds".mysql_error());
						
						
							echo "<table id='dyntable' class='table table-bordered'>
							<thead>
							<tr>
							<tr>
                            <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'>केलेली कार्यवाही </th>
                            <th class='head1 center'>पत्राची स्थिती </th>
							<th class='head0 center'>पाठवलेली/अद्यावत <br>केलेली दि.  </th>
							</tr>
							</thead>";
							while($test = mysql_fetch_array($result222))
							{	
								$dpt_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
								$dis_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
								$updt= date('d-m-Y',strtotime($test['update_date']));
								$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
								$id1 = $test['ltr_inword_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$sts=$test['ltr_status'];
								$depti=$test['dept_id_from'];
								$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
								echo "<tr class='gradeX'>
								<td class='center'>".$test['ltr_inword_no']."<br>".$rcv_dt."</td>
								<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
								<td class='center'>".$dept['dept_nm']."<br>".$test['dpt_inword_no']."</font><br>".$dpt_date."</td>";
								if($test['desk_approval']=='pending')
								{
									echo "<td class='center'><font color='red'>डेस्कने स्वीकारणे बाकी </font><br>".$rec_date ."</td>"; 
								}
								else
								{
									echo "<td class='center'>".$test['desk_ltr_inword_no']."</font><br>".$rec_date ."</td>";
								}
								echo "<td class='center'>".$test['subject']."</td>
								<td class='center'>".$test['sender_name']."</td>";
								/////////////////////////////////////////////////
								if($test['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी</font></td>"; 
								}
								else
								{
									echo "<td class='center'>".$test['action_taken']."</td>";
								}
								///////////////////////////////////////////////////
								if($test['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी</font></td>"; 
								}
								else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
								{
									echo "<td class='center'>".$test['ltr_status']."</td>";
								}
								else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='transferred')
								{
									$todeptid=$test['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);
									echo "<td class='center'>".$test['ltr_approval']." to<br>".$dept['dept_nm']."</td>";
								}
								else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='transferred_todesk')
								{
									$todsk=$test['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{
									echo "<td class='center'>".$test['ltr_status']."</td>";
								}
								//////////////////////////////////////////////////////
								if($sts=='dispatched')
								{
									echo "<td class='center'>".$dis_date."</font></td>";
								}
								else if($sts=='updated'){
									echo "<td class='center'>".$updt."</font></td>";
								}
								else if($sts=='')
								{
									echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी</font></td>"; 
								}
								echo "</tr>";
							}			
							//mysql_close();
							echo"   </tbody>
							</table>";
							
							
							echo "<div id='divToPrint' style='display:none;'>";
							
							$qx= mysql_query("SELECT * FROM desk_master WHERE desk_id = (select desk_id from login where login_id='$username')");
							$rwx=mysql_fetch_array($qx);
							
							echo "<center><h4>".$rwx['desk_nm']." चे वारंवार येणाऱ्या पत्राचे रिपोर्ट्स </h4></center>";
							
							echo "<table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='9'><center><h4>". $rwx['desk_nm'] ." चे वारंवार येणाऱ्या पत्राचे रिपोर्ट्स  </h4></center></td></tr>";
							
							convert_marathi();
							$result222=mysql_query("SELECT i.ltr_inword_no, i.receive_dt, i.ref_no, i.ref_dt, t.dpt_inword_no, t.dpt_ltr_rec_dt, d.desk_ltr_inword_no, d.desk_ltr_rec_dt, i.sender_name, i.subject, d.ltr_approval, d.ltr_status, d.action_taken, d.update_date, d.dispatched_dt, t.dept_id_from, t.sent_to_desk_dt, t.assign_dpt, t.desk_approval, di.dept_id_to, di.dsk_id_to
							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 d ON d.dpt_ltr_id = t.dpt_ltr_id 
							LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = d.desk_ltr_id 
							where d.desk_id_from=(select desk_id from login where login_id='$username') 
							AND i.sender_name='$sender_name'
							AND i.mobile_no='$mobile_no' ") or die("sdfdfds".mysql_error());
							
							echo "<tr>
                            <th>पोलीस अधिक्षक <br> कार्यालय<br>आवक_क्रमांक</th>
                            <th>संदर्भ पाठवलेली<br>क्रमांक_व_दिनांक</th>
							<th>विभागीय आवक क्र.<br>आवक_दिनांक</th>
							<th>डेस्कचा आवक क्र <br>प्राप्त_दिनांक</th>
                            <th>विषय</th>
							<th>कोणाकडून <br>प्राप्त_झाला</th>
							<th>केलेली कार्यवाही </th>
                            <th>पत्राची स्थिती </th>
							<th>पाठवलेली/अद्यावत <br>केलेली_प्राप्त </th>
							</tr>
							</thead>";
							while($test = mysql_fetch_array($result222))
							{	
								$dpt_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
								$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
								$rec_date 		= date('d-m-Y',strtotime($test['sent_to_desk_dt']));
								$dis_date 		= date('d-m-Y',strtotime($test['dispatched_dt']));
								$updt= date('d-m-Y',strtotime($test['update_date']));
								$id1 = $test['ltr_inword_no'];
								$id2 = $test['assign_dept'];
								$id3 = $test['sandarbh_prakar'];
								$sts=$test['ltr_status'];
								
								$depti=$test['dept_id_from'];
								$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("".mysql_error());
									$dept=mysql_fetch_array($qdpt);
								echo "<tr>
								<td style='text-align:center;'>".$test['ltr_inword_no']."</td>
								<td style='text-align:center;'>".$test['ref_no']."</font><br>".$ref_date."</td>
								<td style='text-align:center;'>".$dept['dept_nm']."<br>".$test['dpt_inword_no']."</font><br>".$dpt_date."</td>";
								
								if($test['desk_approval']=='pending')
								{
									echo "<td class='center'>डेस्कने स्वीकारणे बाकी <br>".$rec_date ."</td>"; 
								}
								else
								{
									echo "<td class='center'>".$test['desk_ltr_inword_no']."</font><br>".$rec_date ."</td>";
								}
								echo "<td style='text-align:center;'>".$test['subject']."</td>
								<td style='text-align:center;'>".$test['sender_name']."</td>";
								
								if($test['ltr_status']=='')
								{
									echo "<td class='center'>कार्यवाही करणे बाकी </td>"; 
								}
								else
								{
									echo "<td class='center'>".$test['action_taken']."</td>";
								}
								
								if($test['ltr_status']=='')
								{
									echo "<td class='center'>कार्यवाही करणे बाकी </td>"; 
								}
								else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='Approve')
								{
									echo "<td class='center'>".$test['ltr_status']."</td>";
								}
								else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='transferred')
								{
									$todeptid=$test['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);
									echo "<td class='center'>".$test['ltr_approval']." to<br>".$dept['dept_nm']."</td>";
								}
								else if($test['ltr_status']=='dispatched' && $test['ltr_approval']=='transferred_todesk')
								{
									$todsk=$test['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{
									echo "<td class='center'>".$test['ltr_status']."</td>";
								}
								///////////////////////
								if($sts=='dispatched')
								{
									echo "<td class='center'>".$dis_date."</font></td>";
								}
								else if($sts=='updated'){
									echo "<td class='center'>".$updt."</font></td>";
								}
								else if($sts=='')
								{
									echo "<td class='center'>कार्यवाही करणे बाकी </td>"; 
								}
								echo "</tr>";
							}			
							//mysql_close();
							echo"   </tbody>
							</table></div>";
							?>
                    </tbody> 
                </table>
				<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 />
                
			<!--##################### Displaying Approved Letters InData Table To Perform Action ########-->
                <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
