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

$type= $_REQUEST['type'];

if($type=='tpo')
{
	include_once('dashboard_tapal.php');
}
else if($type=='bdo')
{
	include_once('dashboard_bdo.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();
					/*
						$result = mysql_query("SELECT t.action_taken, 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, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, 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 i.sender_name='$sender_name'
						AND i.mobile_no='$mobile_no'
						AND t.dept_id_from = ( SELECT dept_id from login where login_id = '$username' )") or die("cccc".mysql_error());
					*/
					
						$result = mysql_query("SELECT t.action_taken, 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, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, 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 i.sender_name='$sender_name'
						AND i.mobile_no='$mobile_no'
						") or die("cccc".mysql_error());
						
						echo"<table id='dyntable' class='table table-bordered'>";
							echo"<thead>
									<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>
								</thead>";
							while($rws = mysql_fetch_array($result))
							{
								$ltrid=$rws['ltr_id'];
								$dptltrid=$rws['dpt_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);
								}
								################# convert date in suitable format ##########################
								
								$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'><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']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else
								{
									echo "<td class='center'>".$rws['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								if($rws['ltr_status']=='')
								{
									echo "<td class='center'><font color='red'>"."कार्यवाही करणे बाकी "."</font></td>";
								}
								else if($rws['status']=='transferred')
								{
									echo "<td class='center'>".$rws['status']."</td>";
								}
								else if($rws['status']=='dispatched')
								{
									echo "<td class='center'>".$rws['status']."</td>";
								}
								else if($rws['status']=='approve' && $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>";
								}
								else if($rws['ltr_status']=='updated')
								{
									echo "<td class='center'>".$rws['outword_no']."<br>अपडेट केले</td>";
								}
								else if($rws['dispatched_to']!='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws['outword_no']."<br>".$rws['addressed_to']."</td>";
								}
						
								echo "</td></tr>";
							}
							echo "</tbody>
							</table>";
							
						?>
							
							<br>
							<p>	
								<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
								<input type="button" class="btn" onclick="tableToExcel('export', 'W3C Example Table')" value="Export to Excel"></center>
							</p>
							
							<?php
							
							echo "<div id='divToPrint' style='display:none;'>";
							
							//$qx= mysql_query("SELECT * FROM department_master WHERE dept_id = (select dept_id from login where login_id='$username')");
							//$rwx=mysql_fetch_array($qx);
							
								echo "<center><h4> वारंवार येणाऱ्या पत्राचे रिपोर्ट्स </h4></center>";
							
							
							
							
							echo "<table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='9'><center><h4> वारंवार येणाऱ्या पत्राचे रिपोर्ट्स  </h4></center></td></tr>";
							
							convert_marathi();
							$result = mysql_query("SELECT t.action_taken, 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, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, 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 i.sender_name='$sender_name'
							AND i.mobile_no='$mobile_no' ") or die("cccc".mysql_error());
							
							
							
							echo"<tr>	
									<th>विभागीय आवक_क्र. <br>आवक_दिनांक</th>
									<th>पोलीस अधिक्षक <br> कार्यालय<br>आवक_क्र.<br>आवक_दिनांक</th>
									<th>संदर्भ_क्र.<br>प्राप्त_दिनांक</th>                          
									<th>कोणाकडून_प्राप्त<br>विषय </th>                      
									<th>केलेली <br>कार्यवाही </th>
									<th>पत्राची स्थिती </th>
									<th>जावक_क्रमांक<br> व्यक्तीचे नाव </th>
								</tr>";
								
							while($rws = mysql_fetch_array($result))
							{
								$ltrid=$rws['ltr_id'];
								$dptltrid=$rws['dpt_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);
								}
								################# convert date in suitable format ##########################
								
								$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']=='')
								{
									echo "<td class='center'> कार्यवाही करणे बाकी </td>";
								}
								else
								{
									echo "<td class='center'>".$rws['action_taken']."</td>";
								}
								######################### For Letter Status #################################
								if($rws['ltr_status']=='')
								{
									echo "<td class='center'>कार्यवाही करणे बाकी </td>";
								}
								else if($rws['status']=='transferred')
								{
									echo "<td class='center'>".$rws['status']."</td>";
								}
								else if($rws['status']=='dispatched')
								{
									echo "<td class='center'>".$rws['status']."</td>";
								}
								else if($rws['status']=='approve' && $rws['ltr_status']=='updated')
								{
									echo "<td class='center'>".$rws['ltr_status']."</td>";
								}
								
								##############################################################################
								if($rws['dispatched_to']=='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'> कार्यवाही करणे बाकी </td>";
								}
								else if($rws['ltr_status']=='updated')
								{
									echo "<td class='center'>".$rws['outword_no']."<br>अपडेट केले</td>";
								}
								else if($rws['dispatched_to']!='' && $rws['ltr_status']!='updated')
								{
									echo "<td class='center'>".$rws['outword_no']."<br>".$rws['addressed_to']."</td>";
								}
						
								echo "</td></tr>";
							}
							
							echo "</tbody></table></div>";
							
						?>
				
				
              <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>
