<!DOCTYPE html>
<?php 
include('dashboard_desk.php');
require_once('convert_marathi.php');
######################################## Display Priority Wise Report To Desk ####################################################
$username = $_SESSION['User_Name'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript">     
function PrintDiv() {    
var divToPrint = document.getElementById('divToPrint');
var popupWin = window.open('', '_blank', 'width=600,height=600');
popupWin.document.open();
popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
popupWin.document.close();
}
</script>
<script src="tableToExcel.js"></script>
</head>
<body>
<div class="mainwrapper">   
    <div class="rightpanel">
            <ul class="breadcrumbs">
				<li><a href=""><i class="iconfa-home"></i></a> <span class="separator"></span></li>
				<li><a href="">Tables</a> <span class="separator"></span></li>
				<li>प्राधान्यानुसार रिपोर्ट्स </li>
			</ul>
			<div class="pageheader">
				<div class="pageicon"><span class="iconfa-table"></span></div>
				<div class="pagetitle">
					<h5>Tables</h5>
					<h1>प्राधान्यानुसार रिपोर्ट्स  </h1>
				</div>
			</div><!--pageheader-->
			<div class="maincontent">
				<div class="maincontentinner">
					<?php
					$qx= mysql_query("SELECT * FROM desk_master WHERE desk_id = (select desk_id from login where login_id='$username')") or die("".mysql_error());
					$rwx=mysql_fetch_array($qx) or die("".mysql_error());;
					echo "<h4 class='widgettitle'>".$rwx['desk_nm']." चे प्राधान्यानुसार रिपोर्ट्स </h4>";?>
					<form method="post" action="">
						<?php 		
							$id=$_REQUEST['id'];
							####################################### Display Counter #########################################
							if($id=="")
							{
								convert_marathi();
								$qre=("SELECT tapal_to_dpt_transaction.desk_id,
								incoming_letters_transaction.priority_days, COUNT(*) AS TOTAL FROM  incoming_letters_transaction,tapal_to_dpt_transaction WHERE tapal_to_dpt_transaction.desk_id=(select desk_id from login where login_id='$username') AND incoming_letters_transaction.priority_days!='0' and tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id GROUP BY incoming_letters_transaction.priority_days");
								
								$rsut=mysql_query($qre) or die("".mysql_error());
								echo "<table id='dyntable' class='table table-bordered'>	
								<thead>
								<tr>
									<th class='head0 center' style='width:160px;'>प्राधान्य दिवस </th>
									<th class='head1 center'>एकूण </th>
								</tr>
								</thead>
								<tbody>";
								while($rws = mysql_fetch_array($rsut))
								{
									$id=$rws['priority_days'];
									echo "<tr class='gradeX'>";
									echo "<td class='center'><a href='report_priority.php?id=$id'>".$rws['priority_days']."</a></td><td class='center'>". $rws['TOTAL']."</td> </tr>";                
								}?>
								</tbody>
								</table>
							<?php
								echo "<div id='divToPrint' style='display:none;'>
									<table id='export' border='1px' style='margin-left:50px;'>
									<tr><td colspan='9'><center><h4>". $rwx['desk_nm']." चे प्राधान्यानुसार रिपोर्ट्स </h4></center></td></tr>";
								convert_marathi();
								$qre=("SELECT tapal_to_dpt_transaction.desk_id, priority_days, COUNT(*) AS TOTAL FROM  incoming_letters_transaction,tapal_to_dpt_transaction WHERE tapal_to_dpt_transaction.desk_id=(select desk_id from login where login_id='$username') AND incoming_letters_transaction.priority_days!='0' and tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id GROUP BY incoming_letters_transaction.priority_days");
								$rsut=mysql_query($qre) or die("".mysql_error());
								echo "<tr>
								<th>प्राधान्य दिवस </th>
								<th>एकूण </th>
								</tr>
								</thead>";
								while($rws = mysql_fetch_array($rsut))
								{
									$id=$rws['priority_days'];
									echo "<tr>";
									echo "<td style='text-align:center;'>".$rws['priority_days']."</a></td><td style='text-align:center;'>". $rws['TOTAL']."</td></tr>";                
								}
								echo "</table></div>";
							} ######################## End Of Display Counter ################################	
							
							else if( $id != "")
							{
								################################ Display Details #################################
								convert_marathi();
								echo "<form name='dept_sandarbh' action='' method='post'>
								<div align='center'><br><table align='center' cellpadding='2' cellspacing='0' class='myClass'>
								<table>
									<tr>											  
										<td align='center'><label style='width:110px;'>Start date</label></td>
										<td align='center'><input type='text' name='start_date' class='input-small'/></td>
										<td align='center'><label style='width:110px;'>End Date</label></td>
										<td align='center'><input type='text' name='end_date' class='input-small'/></td>
									</tr>
									<tr>
										<td colspan='6'>
										<div align='center'>
											<input type='submit' onClick='return sadyasthitiDates()' name='ok' value='GO'/>
											<input type='reset' value='CLEAR' name='clear'/>
										</div>
										</td>
									</tr>
								</table>
							</div>				
							</form>
							<form action='' method='post'>";
							$date123	= $_POST['start_date'];
							$date1	= date('Y-m-d',strtotime($date123));
							$date223	= $_POST['end_date'];
							$date2	= date('Y-m-d',strtotime($date223));
							//$date22	= date('d-m-Y',strtotime($date2));
							if($date123==''&& $date223=='')
							{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id1 = $date1;
								$id2= $date2;
								/*$result222=mysql_query("SELECT * FROM desk_transaction,incoming_letters_transaction,tapal_to_dpt_transaction where tapal_to_dpt_transaction.desk_id=(select desk_id from login where login_id='$username') AND priority_days='$id' AND desk_transaction.dpt_ltr_id=tapal_to_dpt_transaction.dpt_ltr_id AND incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id") or die("sdfdfds".mysql_error());*/
								$result222=mysql_query("SELECT d.desk_ltr_rec_dt, t.dpt_ltr_rec_dt, i.ref_dt, i.receive_dt, d.desk_ltr_inword_no, t.dpt_inword_no, i.ltr_inword_no, i.ref_no, i.sender_name, i.subject, d.action_taken,t.dept_id_from
								FROM desk_transaction d,incoming_letters_transaction i,tapal_to_dpt_transaction t
								where t.desk_id=(select desk_id from login where login_id='$username') 
								AND i.priority_days='$id' 
								AND d.dpt_ltr_id=t.dpt_ltr_id 
								AND i.ltr_id=t.ltr_id") or die("sdfdfds".mysql_error());
															
							/*	$result222=mysql_query("SELECT * FROM incoming_letters_transaction,tapal_to_dpt_transaction where tapal_to_dpt_transaction.desk_id=(select desk_id from login where login_id='$username') AND priority_days='$id' AND incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id") or die("sdfdfds".mysql_error());*/
								
							}
							else{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id1 = $date1;
								$id2= $date2;
								/*$result222=mysql_query("SELECT * FROM desk_transaction,incoming_letters_transaction,tapal_to_dpt_transaction where tapal_to_dpt_transaction.desk_id=(select desk_id from login where login_id='$username') AND priority_days='$id' AND desk_transaction.dpt_ltr_id=tapal_to_dpt_transaction.dpt_ltr_id AND incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND (incoming_letters_transaction.receive_dt BETWEEN '$date1' AND '$date2')") or die("zzzzz".mysql_error());*/
								$result222=mysql_query("SELECT d.desk_ltr_rec_dt, t.dpt_ltr_rec_dt, i.ref_dt, i.receive_dt, d.desk_ltr_inword_no, t.dpt_inword_no, i.ltr_inword_no, i.ref_no, i.sender_name, i.subject, d.action_taken,t.dept_id_from
								FROM desk_transaction d,incoming_letters_transaction i,tapal_to_dpt_transaction t
								where t.desk_id=(select desk_id from login where login_id='$username') 
								AND i.priority_days='$id' 
								AND d.dpt_ltr_id=t.dpt_ltr_id 
								AND i.ltr_id=t.ltr_id AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
							}
								?> 
								<table id="dyntable" class="table table-bordered">	
									<thead>
									<tr>
										<th class="head0 center">डेस्कचा आवक क्र <br>डेस्कला प्राप्त दि.</th>
										<th class="head1 center">विभागीय आवक क्र.<br>विभागीय आवक दि.</th>
										<th class="head0 center">आवक_क्रमांक<br>आवक_ दि.</th>
										<th class="head1 center">संदर्भ   क्र.<br>संदर्भ  दि.</th>                          
										<th class="head0 center">कोणाकडून प्राप्त <br>झाला</th>
										<th class="head0 center">विषय</th>                         
										<th class="head1 center">केलेली कार्यवाही  </th>
									</tr>
									</thead>
									<?php
									while($rws = mysql_fetch_array($result222))
									{
										$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);
										
										$depti=$rws['dept_id_from'];
										$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("aaaaaa".mysql_error());
										$dept=mysql_fetch_array($qdpt);
										?>
										<tr class="gradeX">
										<?php 
										echo "<td class='center'>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1." </td>
										<td class='center'>".$dept['dept_nm']."<br>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
										echo "<td class='center'>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
										<td class='center'>".$rws['ref_no']."<br>".$refdt1."</td>
										<td class='center'>".$rws['sender_name']."</td><td class='center'>".$rws['subject']."</td>";
										if($rws['action_taken']=='')
										{
										echo "<td class='center'><font color='red'>कार्यवाही करणे बाकी </font></td>";
										}
										else
										{
										echo "<td class='center'>".$rws['action_taken']."</td>";
										}
										echo" </select></tr>";
									}
									//mysql_close();
									echo"   </tbody>
									</table>";
									
								echo "<div id='divToPrint' style='display:none;'>
									<table id='export' border='1px' style='margin-left:50px;'>
									<tr><td colspan='9'><center><h4>". $rwx['desk_nm']." चे प्राधान्यानुसार रिपोर्ट्स </h4></center></td></tr>";
								if($date123==''&& $date223=='')
							{
								convert_marathi();
								$result222=mysql_query("SELECT d.desk_ltr_rec_dt, t.dpt_ltr_rec_dt, i.ref_dt, i.receive_dt, d.desk_ltr_inword_no, t.dpt_inword_no, i.ltr_inword_no, i.ref_no, i.sender_name, i.subject, d.action_taken,t.dept_id_from
								FROM desk_transaction d,incoming_letters_transaction i,tapal_to_dpt_transaction t
								where t.desk_id=(select desk_id from login where login_id='$username') 
								AND i.priority_days='$id' 
								AND d.dpt_ltr_id=t.dpt_ltr_id 
								AND i.ltr_id=t.ltr_id") or die("sdfdfds".mysql_error());
							}
							else
							{
								convert_marathi();
								$result222=mysql_query("SELECT d.desk_ltr_rec_dt, t.dpt_ltr_rec_dt, i.ref_dt, i.receive_dt, d.desk_ltr_inword_no, t.dpt_inword_no, i.ltr_inword_no, i.ref_no, i.sender_name, i.subject, d.action_taken,t.dept_id_from
								FROM desk_transaction d,incoming_letters_transaction i,tapal_to_dpt_transaction t
								where t.desk_id=(select desk_id from login where login_id='$username') 
								AND i.priority_days='$id' 
								AND d.dpt_ltr_id=t.dpt_ltr_id 
								AND i.ltr_id=t.ltr_id AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
							}
								echo "	<tr>
										<th>डेस्कचा आवक क्र <br>डेस्कला प्राप्त दि.</th>
										<th>विभागीय आवक क्र.<br>विभागीय आवक दि.</th>
										<th>आवक_क्रमांक<br>आवक_ दि.</th>
										<th>संदर्भ   क्र.<br>संदर्भ  दि.</th>                          
										<th>कोणाकडून प्राप्त <br>झाला</th>
										<th>विषय</th>                         
										<thकेलेली कार्यवाही  </th>
									</tr>";
									while($rws = mysql_fetch_array($result222))
									{
										$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);
										
										$depti=$rws['dept_id_from'];
										$qdpt=mysql_query("Select dept_nm from department_master Where dept_id='$depti'") or die("aaaaaa".mysql_error());
										$dept=mysql_fetch_array($qdpt);
										
										echo "<tr>";
										echo "<td style='text-align:center;'>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1." </td>
										<td style='text-align:center;'>".$dept['dept_nm']."<br>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
										echo "<td style='text-align:center;'>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
										<td style='text-align:center;'>".$rws['ref_no']."<br>".$refdt1."</td>
										<td style='text-align:center;'>".$rws['sender_name']."</td><td>".$rws['subject']."</td>";
										if($rws['action_taken']=='')
										{
										echo "<td style='text-align:center;'>कार्यवाही करणे बाकी </td>";
										}
										else
										{
										echo "<td style='text-align:center;'>".$rws['action_taken']."</td>";
										}
										echo"</tr>";
									}
									//mysql_close();
										echo"</tbody></table></div>";
									
							}
							
							################## End Of Display Details ############################################
						?>
						<br>
						<p>	
							<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
							<input type="button" class="btn" onclick="tableToExcel('export', 'W3C Example Table')" value="Export to Excel"></center>
						</p>
					</form>
					<br /><br />
                    <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
