<!DOCTYPE html>
<?php
$username = $_SESSION['User_Name'];
 require_once('convert_marathi.php');
$no=$_GET['no'];
$deskid=$_GET['deskid'];
$dptid=$_GET['deptid'];
################################################# Desk Wise Report For Tapal ##################################################
if($no==2)
{
include('dashboard_tapal.php');	
?>
<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>
					<?php 
					$qryz=mysql_query("Select dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
					$rsz=mysql_fetch_array($qryz);
					
					$qry=mysql_query("Select desk_nm from desk_master where desk_id='$deskid' ");
					$rs=mysql_fetch_array($qry);
					// echo $rs['desk_nm'];
					?>
					
					<h1><?php echo 	$rsz['dept_nm'];?> डेस्क नुसार रिपोर्ट्स </h1>
				</div>
			</div><!--pageheader-->
			<div class="maincontent">
				<div class="maincontentinner">
						<h4 class="widgettitle"><?php echo 	$rsz['dept_nm'];?>डेस्क नुसार रिपोर्ट्स  (  <?php echo $rs['desk_nm'];?>)</h4>
						<form method="post" action="">
							<?php 		
							############################# Display Counter ###################################
							if($deskid=="" && $no==2)
							{
								convert_marathi();
								$qre=("SELECT de.desk_id_from, dm.desk_nm, COUNT(*) AS TOTAL FROM tapal_to_dpt_transaction as t, incoming_letters_transaction as i, desk_transaction as de, desk_master AS dm WHERE i.ltr_id=t.ltr_id AND de.dpt_ltr_id=t.dpt_ltr_id AND de.desk_id_from=dm.desk_id GROUP BY dm.desk_nm");
							 
								$rsut=mysql_query($qre) or die("".mysql_error());
								echo "<table id='dyntable' class='table table-bordered'></colgroup>
								<thead>
								<tr>
								<th class='head0 center' style='width:160px;'>डेस्कचे नाव </th>
								<th class='head1 center'>एकूण</th>
								</tr>
								</thead>";
								while($rws = mysql_fetch_array($rsut))
									{
										$deskid=$rws['desk_id_from'];
										?>
										<tbody>
										<tr class="gradeX">
										<?php 
										echo "<td class='center'><a href='report_dpt_deskwise.php?deskid=$deskid&no=2'>".$rws['desk_nm']."</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>डेस्क नुसार रिपोर्ट्स </h4></center></td></tr>";
								convert_marathi();
								$qre=("SELECT tapal_to_dpt_transaction.desk_id, desk_master.desk_nm, COUNT(*) AS TOTAL FROM tapal_to_dpt_transaction,desk_master,desk_transaction where desk_transaction.desk_id_from=desk_master.desk_id GROUP BY desk_nm");
								$rsut=mysql_query($qre) or die("".mysql_error());
								echo "<tr>
								<th class='head0 center' style='width:160px;'>डेस्कचे नाव </th>
								<th class='head1 center'>एकूण</th>
								</tr>";
								while($rws = mysql_fetch_array($rsut))
									{
										$deskid=$rws['desk_id'];
										echo "<tr><td style='text-align:center;'>".$rws['desk_nm']."</td><td style='text-align:center;'>". $rws['TOTAL']."</td> </tr>";            
									}
								echo "</table>
								</div>";
							} 
							####################################### End Of Display Counter ###########################
						
							############################### Display Details ###################################
							else if( $deskid != "" && $no==2)
							{
								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>";
							$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 de.desk_ltr_id,i.ltr_type, 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, de.ltr_status, i.sender_name, i.ltr_id,i.priority_days, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt
								FROM tapal_to_dpt_transaction as t, incoming_letters_transaction as i, desk_transaction as de 
								WHERE i.ltr_id=t.ltr_id
								AND de.dpt_ltr_id=t.dpt_ltr_id 
								AND de.desk_id_from='$deskid'") 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 de.desk_ltr_id,i.ltr_type, 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, de.ltr_status, i.sender_name, i.ltr_id,i.priority_days, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt FROM tapal_to_dpt_transaction as t, incoming_letters_transaction as i, desk_transaction as de WHERE i.ltr_id=t.ltr_id AND de.dpt_ltr_id=t.dpt_ltr_id AND de.desk_id_from='$deskid' AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
							}
								$count10=mysql_num_rows($result222);
								echo "
										<table id='dyntable' class='table table-bordered'>	
											<thead>
											<tr>
											<th class='head0 center'>पोलीस अधिक्षक कार्यालय <br>आवक_क्रमांक<br>आवक_दिनांक</th>
											<th class='head1 center'>संदर्भ <br>प्राप्त_दिनांक</th>
											<th class='head1 center'>विभाग<br>प्राप्त_दिनांक</th>
											<th class='head0 center'>विषय</th>
											<th class='head1 center'>कोणाकडून प्राप्त झाला</th> 
											<th class='head1 center'>डेस्कचा आवक क्र  </th>
											<th class='head0 center'>डेस्कला प्राप्त दि. </th>
											<th class='head1 center'>केलेली कार्यवाही</th>
											</tr>
											</thead>";
											while($test = mysql_fetch_array($result222))
											{
												$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
												$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
												if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
												{
													$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
												}
												else if($test['sent_to_desk_dt']!='')
												{
													$dis_date="--" ;			
												}
												$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
												
												$deskid=$test['desk_id_from'];
												
												echo "<tr class='gradeX'>
												<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
												<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
												<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
												<td class='center'>".$test['subject']."</td>
												<td class='center'>".$test['sender_name']."</td>";
										/*		if($test['priority_days']=='0')
												{
													echo "<td class='center'>"."--"."</td>";
												}
												else if($test['priority_days']>'0')
												{
													echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=2'>".$test['priority_days']."</a></td>";		
												}  */
												$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
												$rs09=mysql_query($qry09) or die("assssss".mysql_error());
												$rw09=mysql_fetch_array($rs09);
												$desknm=$rw09['desk_nm'];
												//////////////////////////////////////////////////////
												if($desknm!='')
												{
													echo "<td class='center'>".$test['desk_ltr_inword_no']."</td>";}
												else if($desknm=='')
												{
													echo "<td class='center'>डेस्क लावणे बाकी </td>";
												}
												////////////////////////////////////////////////////
												echo "<td class='center'>".$dis_date."</font></td>";
												/////////////////////////////////////////////////////
												if($test['ltr_status']=='closed')
												{
													$deptinwardno=$test['dpt_inword_no'];
													$q=mysql_query("SELECT rtn_to_dsk from returned_from_desk where dpt_inword_no='$deptinwardno' AND returned_from='$deskid' ");
													$rs=mysql_fetch_array($q);
													if($rs['rtn_to_dsk']!='')
													{
														$returndskid=$rs['rtn_to_dsk'];
														$qr=mysql_query("SELECT desk_nm from desk_master where desk_id='$returndskid' ");
														$rslt=mysql_fetch_array($qr);
														$returnedto=$rslt['desk_nm'];
													}
													else
													{
														$qr=mysql_query("SELECT dept_nm from department_master where dept_id ='$dptid' ");
														$rslt=mysql_fetch_array($qr);
														$returnedto=$rslt['dept_nm'];
													}
													echo "<td class='center'>Letter Returned To <br>".$returnedto."</td>";
												}
												else if($test['ltr_status']=='')
												{
														echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
												}
												else
												{
													echo "<td class='center'>".$test['action_taken']."</td>";
												}
												echo "</tr>";
											}
										echo"   </tbody>
										</table>";
								echo "<div id='divToPrint' style='display:none;'>
							<table id='export' border='1px' style='margin-left:150px;'>
							<tr><td colspan='9'><center> डेस्क नुसार रिपोर्ट्स  <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";	
							echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
							convert_marathi();				
							if($date123==''&& $date223=='')
							{
								$id1 = $date1;
								$id2= $date2;
								$result222=mysql_query("SELECT de.desk_ltr_id,i.ltr_type, 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, de.ltr_status, i.sender_name, i.ltr_id,i.priority_days, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt FROM tapal_to_dpt_transaction as t, incoming_letters_transaction as i, desk_transaction as de WHERE i.ltr_id=t.ltr_id AND de.dpt_ltr_id=t.dpt_ltr_id AND de.desk_id_from='$deskid'") or die("sdfdfds".mysql_error());
							}
							else
							{
								$id1 = $date1;
								$id2= $date2;
								$result222=mysql_query("SELECT de.desk_ltr_id,i.ltr_type, 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, de.ltr_status, i.sender_name, i.ltr_id,i.priority_days, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc,t.sent_to_desk_dt FROM tapal_to_dpt_transaction as t, incoming_letters_transaction as i, desk_transaction as de WHERE i.ltr_id=t.ltr_id AND de.dpt_ltr_id=t.dpt_ltr_id AND de.desk_id_from='$deskid' AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
							}
								$count10=mysql_num_rows($result222);
								echo "<tr>
											<th>पोलीस अधिक्षक कार्यालय<br>आवक_क्रमांक<br>आवक_दिनांक</th>
											<th>संदर्भ <br>प्राप्त_दिनांक</th>
											<th>विभाग<br>प्राप्त_दिनांक</th>
											<th>विषय</th>
											<th>कोणाकडून प्राप्त_झाला</th> 
											<th>डेस्कचा आवक_क्रमांक </th>
											<th>डेस्कला प्राप्त_दिनांक</th>
											<th>केलेली कार्यवाही</th>
											</tr>";
											while($test = mysql_fetch_array($result222))
											{
												$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
												$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
												if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
												{
													$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
												}
												else if($test['sent_to_desk_dt']!='')
												{
													$dis_date="--" ;			
												}
												$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
												
												$deskid=$test['desk_id_from'];
												
												echo "<tr class='gradeX'>
												<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
												<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
												<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
												<td class='center'>".$test['subject']."</td>
												<td class='center'>".$test['sender_name']."</td>";
											/*	if($test['priority_days']=='0')
												{
													echo "<td class='center'>"."--"."</td>";
												}
												else if($test['priority_days']>'0')
												{
													echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=2'>".$test['priority_days']."</a></td>";		
												} */
												$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
												$rs09=mysql_query($qry09) or die("assssss".mysql_error());
												$rw09=mysql_fetch_array($rs09);
												$desknm=$rw09['desk_nm'];
												//////////////////////////////////////////////////////
												if($desknm!='')
												{
													echo "<td class='center'>".$test['desk_ltr_inword_no']."</td>";}
												else if($desknm=='')
												{
													echo "<td class='center'>डेस्क लावणे बाकी </td>";
												}
												////////////////////////////////////////////////////
												echo "<td class='center'>".$dis_date."</font></td>";
												/////////////////////////////////////////////////////
												if($test['ltr_status']=='closed')
												{
													$deptinwardno=$test['dpt_inword_no'];
													$q=mysql_query("SELECT rtn_to_dsk from returned_from_desk where dpt_inword_no='$deptinwardno' AND returned_from='$deskid' ");
													$rs=mysql_fetch_array($q);
													if($rs['rtn_to_dsk']!='')
													{
														$returndskid=$rs['rtn_to_dsk'];
														$qr=mysql_query("SELECT desk_nm from desk_master where desk_id='$returndskid' ");
														$rslt=mysql_fetch_array($qr);
														$returnedto=$rslt['desk_nm'];
													}
													else
													{
														$qr=mysql_query("SELECT dept_nm from department_master where dept_id ='$dptid' ");
														$rslt=mysql_fetch_array($qr);
														$returnedto=$rslt['dept_nm'];
													}
													echo "<td class='center'>Letter Returned To <br>".$returnedto."</td>";
												}
												else if($test['ltr_status']=='')
												{
														echo "<td class='center'> कार्यवाही करणे बाकी </td>";
												}
												else
												{
													echo "<td class='center'>".$test['action_taken']."</td>";
												}
												echo "</tr>";
											}
										echo "</table>
									</div></form>";	
							}?><br>
								<p>	
									<center>
									<input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
									<input type="button" class="btn" onclick="tableToExcel('export', 'Sandarbha-Nusar Report')" value="Export to Excel"></center>
								</p>
						</form>
                <br /><br />              
                        <?php include_once('footer.php'); ?>
					</div><!--maincontentinner-->
				</div><!--maincontent-->
			</div><!--rightpanel-->
		</div><!--mainwrapper-->
	</body>
	</html>
		<?php
}//if tapal user
###################################### End Of Desk Wise Report For Tapal ####################################

######################################## Desk Wise Report For Department ########################################
else if($no==1)
{
	include('dashboard_department.php');	
	?>
	<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 type="text/javascript">     
	var tableToExcel = (function() {
	var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
	return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
	}
	})()
	</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>
					<?php 
					$qryz=mysql_query("Select dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
					$rsz=mysql_fetch_array($qryz);
					
					$qry=mysql_query("Select desk_nm from desk_master where desk_id='$deskid' ");
					$rs=mysql_fetch_array($qry);
					?>
					<h1><?php echo 	$rsz['dept_nm'];?> चे डेस्क नुसार रिपोर्ट्स </h1>
				</div>
			</div><!--pageheader-->
			<div class="maincontent">
				<div class="maincontentinner">
					<h4 class="widgettitle"><?php echo 	$rsz['dept_nm'];?> चे डेस्क नुसार रिपोर्ट्स  ( <?php echo $rs['desk_nm'];?>  )  </h4>
					<form method="post" action="">
						<?php 		
						####################################### Display Counter ###################################
						if($deskid=='' && $no==1)
						{
								convert_marathi();
								/*$qre=("SELECT tapal_to_dpt_transaction.desk_id, tapal_to_dpt_transaction.dept_id_from, desk_master.desk_nm, COUNT(*) AS TOTAL FROM tapal_to_dpt_transaction, desk_master where tapal_to_dpt_transaction.dept_id_from=(select dept_id from login where login_id='$username') AND tapal_to_dpt_transaction.desk_id=desk_master.desk_id GROUP BY desk_nm") or die("".mysql_error());*/
							
							/*Display total approved by dept
							$qre=("SELECT t.desk_id, t.dept_id_from, dm.desk_nm, COUNT( * ) AS TOTAL
							FROM tapal_to_dpt_transaction t, desk_master dm, incoming_letters_transaction i, desk_transaction de
							WHERE t.dept_id_from = (
														SELECT dept_id
														FROM login
														WHERE login_id = '$username' )
							AND i.ltr_id = t.ltr_id
							AND de.dpt_ltr_id = t.dpt_ltr_id
							AND (t.status = 'approve' || t.status = 'pending')
							AND t.desk_id = dm.desk_id
							GROUP BY desk_nm") or die("".mysql_error());
								
								$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>";
								while($rws = mysql_fetch_array($rsut))
									{
										$deskid=$rws['desk_id'];
										?>
										<tbody>
											<tr class="gradeX">
											<?php 
											echo "<td class='center'><a href='report_dpt_deskwise.php?deskid=$deskid&no=1'>".$rws['desk_nm']."</a></td><td class='center'>". $rws['TOTAL']."</td> </tr>";    
									}*/
									$qry=mysql_query("SELECT desk_nm,desk_id from  desk_master where dept_id=(
														SELECT dept_id
														FROM login
														WHERE login_id = '$username' ) ");
									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($rs=mysql_fetch_array($qry))
									{
										$dskid=$rs['desk_id'];
										$q=mysql_query("SELECT COUNT( * ) AS TOTAL
										FROM tapal_to_dpt_transaction t,incoming_letters_transaction i, desk_transaction de
										WHERE de.desk_id_from='$dskid'
										AND i.ltr_id = t.ltr_id
										AND de.dpt_ltr_id = t.dpt_ltr_id
										AND (t.status = 'approve' || t.status = 'pending')");
										$r=mysql_fetch_array($q);
										
										echo "<tr><td class='center'><a href='report_dpt_deskwise.php?deskid=$dskid&no=1'>".$rs['desk_nm']."</a></td>
										<td class='center'>". $r['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>".$rsz['dept_nm']."डेस्क नुसार रिपोर्ट्स </h4></center></td></tr>";
								convert_marathi();
								/*$qre=("SELECT tapal_to_dpt_transaction.desk_id, tapal_to_dpt_transaction.dept_id_from, desk_master.desk_nm, COUNT(*) AS TOTAL FROM tapal_to_dpt_transaction, desk_master where tapal_to_dpt_transaction.dept_id_from=(select dept_id from login where login_id='$username') AND tapal_to_dpt_transaction.desk_id=desk_master.desk_id GROUP BY desk_nm") or die("".mysql_error());*/
								
								$qry=mysql_query("SELECT desk_nm,desk_id from  desk_master where dept_id=(
														SELECT dept_id
														FROM login
														WHERE login_id = '$username' ) ");
									echo "
									<thead>
										<tr>
											<th class='head0 center' style='width:160px;'>डेस्कचे नाव </th>
											<th class='head1 center'>एकूण</th>
										</tr>
									</thead>
									<tbody>";
									while($rs=mysql_fetch_array($qry))
									{
										$dskid=$rs['desk_id'];
										$q=mysql_query("SELECT COUNT( * ) AS TOTAL
										FROM tapal_to_dpt_transaction t,incoming_letters_transaction i, desk_transaction de
										WHERE de.desk_id_from='$dskid'
										AND i.ltr_id = t.ltr_id
										AND de.dpt_ltr_id = t.dpt_ltr_id
										AND (t.status = 'approve' || t.status = 'pending')");
										$r=mysql_fetch_array($q);
										
										echo "<tr><td class='center'><a href='report_dpt_deskwise.php?deskid=$dskid&no=1'>".$rs['desk_nm']."</a></td>
										<td class='center'>". $r['TOTAL']."</td> </tr>";    
									}
									echo "</tbody>
									</table>";
							
					 	}
							######################### End Of Display Counter ###################################
							
							############################# Display Details ###################################
							else if( $deskid != "" && $no==1)
							{
								convert_marathi();
								
								echo "<form method='post' action=''>
									<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 tapal_to_dpt_transaction, incoming_letters_transaction, desk_transaction WHERE incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND desk_transaction.dpt_ltr_id=tapal_to_dpt_transaction.dpt_ltr_id AND tapal_to_dpt_transaction.desk_id='$deskid' AND tapal_to_dpt_transaction.dept_id_from=(select dept_id from login where login_id='$username')") or die("sdfdfds".mysql_error());*/
								
								//accepted by desk
								$result222=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.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.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 t.dept_id_from = (
															SELECT dept_id
															FROM login
															WHERE login_id = '$username' )
								AND de.desk_id_from = '$deskid'
								AND i.ltr_id = t.ltr_id
								AND de.ltr_status!='closed'
								");
							
								//desk not accoepted
								$result2221=mysql_query("SELECT  t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, 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
								WHERE t.dept_id_from = (
															SELECT dept_id
															FROM login
															WHERE login_id = '$username' )
								AND t.desk_id = '$deskid'
								AND t.desk_approval = 'pending' 
								");
								
							}
							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 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.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.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 t.dept_id_from = (
															SELECT dept_id
															FROM login
															WHERE login_id = '$username' )
								AND de.desk_id_from = '$deskid'
								AND i.ltr_id = t.ltr_id
								AND de.ltr_status!='closed'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')");
								
								$result2221=mysql_query("SELECT  t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, 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
								WHERE t.dept_id_from = (
															SELECT dept_id
															FROM login
															WHERE login_id = '$username' )
								AND t.desk_id = '$deskid'
								AND t.desk_approval = 'pending'  
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')");
							}
								echo "<table id='dyntable' class='table table-bordered'>
								<thead>
								<tr>
								<th class='head0 center'>पोलीस अधिक्षक कार्यालय<br>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class='head1 center'>संदर्भ <br>प्राप्त दिनांक</th>
								<th class='head1 center'>विभाग<br>प्राप्त दिनांक</th>
								<th class='head0 center'>विषय</th>
								<th class='head1 center'>कोणाकडून प्राप्त झाला</th> ";
								//echo "<th class='head0 center'>प्राधान्य दिवस</th>
								echo "<th class='head1 center'>डेस्कचा आवक क्र  </th>
								<th class='head0 center'>.डेस्क ला प्राप्त दि. </th>
								<th class='head0 center'>केलेली कार्यवाही</th>
								</tr>
								</thead>";
			
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$dskid=$test['desk_id'];
				
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
								
							/*		if($test['priority_days']=='0')
									{
										echo "<td class='center'>"."--"."</td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=1'>".$test['priority_days']."</a></td>";		
									} */
									
									$qry09="Select desk_nm from desk_master where desk_id='$dskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//////////////////////////////////////////////////////////////////
									 if($desknm!='' && $test['desk_ltr_inword_no']!='')
									{
										echo "<td class='center'>".$test['desk_ltr_inword_no']."</td>";}
									/*else if($desknm=='')
									{
										echo "<td class='center'>डेस्क लावणे बाकी </td>";
									}*/
									else if($desknm!='' && $test['desk_ltr_inword_no']=='')
									{
									
										echo "<td class='center'><font color='red'>देस्क्ने स्वीकारणे बाकी </font></td>";
									}
									echo "<td class='center'>".$dis_date."</font></td>";
									///////////////////////////////////////////////////////////////
									if($test['ltr_status']=='' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									
									echo "</tr>";
								}
								
								while($test = mysql_fetch_array($result2221))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$dskid=$test['desk_id'];
				
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
								
							/*		if($test['priority_days']=='0')
									{
										echo "<td class='center'>"."--"."</td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=1'>".$test['priority_days']."</a></td>";		
									} */
									
									$qry09="Select desk_nm from desk_master where desk_id='$dskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//////////////////////////////////////////////////////////////////
									if($desknm!='' && $test['desk_ltr_inword_no']!='')
									{
										echo "<td class='center'>".$test['desk_ltr_inword_no']."</td>";}
									/*else if($desknm=='')
									{
										echo "<td class='center'>डेस्क लावणे बाकी </td>";
									}*/
									else if($desknm!='' && $test['desk_ltr_inword_no']=='')
									{
									
										echo "<td class='center'><font color='red'>देस्क्ने स्वीकारणे बाकी </font></td>";
									}
									echo "<td class='center'>".$dis_date."</font></td>";
									///////////////////////////////////////////////////////////////
									if($test['ltr_status']=='' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'><font color='red'> कार्यवाही करणे बाकी </font></td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									
									echo "</tr>";
								}
								echo "</tbody>
								</table>";
								
								echo "<div id='divToPrint' style='display:none;'>
							<center><table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='9'><center>".$rsz['dept_nm']." डेस्क नुसार रिपोर्ट्स ( ".$rs['desk_nm']." ) <br>दिनांक ".$date123." पासून दिनांक ".$date223."</center></td></tr>";
							
							echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
							convert_marathi();
							if($date123==''&& $date223=='')
							{
								$id1 = $date1;
								$id2= $date2;
								
								/*$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction, incoming_letters_transaction, desk_transaction WHERE incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND desk_transaction.dpt_ltr_id=tapal_to_dpt_transaction.dpt_ltr_id AND tapal_to_dpt_transaction.desk_id='$deskid' AND tapal_to_dpt_transaction.dept_id_from=(select dept_id from login where login_id='$username')") or die("sdfdfds".mysql_error());*/
								
								//accepted by desk
								$result222=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.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.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 t.dept_id_from = (
															SELECT dept_id
															FROM login
															WHERE login_id = '$username' )
								AND de.desk_id_from = '$deskid'
								AND i.ltr_id = t.ltr_id
								AND de.ltr_status!='closed'
								");
								
								//desk not accoepted
								$result2221=mysql_query("SELECT  t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, 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
								WHERE t.dept_id_from = (
															SELECT dept_id
															FROM login
															WHERE login_id = '$username' )
								AND t.desk_id = '$deskid'
								AND t.desk_approval = 'pending' 
								");
								
							}
							else{
								$id1 = $date1;
								$id2= $date2;
								
								$result222=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.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.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 t.dept_id_from = (
															SELECT dept_id
															FROM login
															WHERE login_id = '$username' )
								AND de.desk_id_from = '$deskid'
								AND i.ltr_id = t.ltr_id
								AND de.ltr_status!='closed'
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')");
								
								$result2221=mysql_query("SELECT  t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, 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
								WHERE t.dept_id_from = (
															SELECT dept_id
															FROM login
															WHERE login_id = '$username' )
								AND t.desk_id = '$deskid'
								AND t.desk_approval = 'pending'  
								AND (i.receive_dt BETWEEN '$date1' AND '$date2')");
							}
								$count10=mysql_num_rows($result222);
			
								echo "<tr>
								<th>पोलीस अधिक्षक कार्यालय<br>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ <br>प्राप्त दिनांक</th>
								<th>विभाग<br>प्राप्त दिनांक</th>
								<th>विषय</th>
								<th>कोणाकडून प्राप्त झाला</th> ";
							//	echo "<th>प्राधान्य दिवस</th>";
								echo "<th>डेस्कचा आवक क्र  </th>
								<th>डेस्क ला प्राप्त दि. </th>
								<th>केलेली कार्यवाही</th>
								</tr>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id'];
				
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
								
							/*		if($test['priority_days']=='0')
									{
										echo "<td class='center'>"."--"."</td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=1'>".$test['priority_days']."</a></td>";		
									} */
									
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//////////////////////////////////////////////////////////////////
									 if($desknm!='' && $test['desk_ltr_inword_no']!='')
									{
										echo "<td class='center'>".$test['desk_ltr_inword_no']."</td>";}
									/*else if($desknm=='')
									{
										echo "<td class='center'>डेस्क लावणे बाकी </td>";
									}*/
									else if($desknm!='' && $test['desk_ltr_inword_no']=='')
									{
									
										echo "<td class='center'>देस्क्ने स्वीकारणे बाकी </td>";
									}
									echo "<td class='center'>".$dis_date."</font></td>";
									///////////////////////////////////////////////////////////////
									if($test['ltr_status']=='' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'> कार्यवाही करणे बाकी </td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									
									echo "</tr>";
								}
								
								while($test = mysql_fetch_array($result2221))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id'];
				
									echo "<tr class='gradeX'>
									<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td class='center'>".$test['subject']."</td>
									<td class='center'>".$test['sender_name']."</td>";
								
							/*		if($test['priority_days']=='0')
									{
										echo "<td class='center'>"."--"."</td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td class='center'><a href='report_dpt_priority.php?id=$test[priority_days]&no=1'>".$test['priority_days']."</a></td>";		
									} */
									
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									//////////////////////////////////////////////////////////////////
									if($desknm!='' && $test['desk_ltr_inword_no']!='')
									{
										echo "<td class='center'>".$test['desk_ltr_inword_no']."</td>";}
									/*else if($desknm=='')
									{
										echo "<td class='center'>डेस्क लावणे बाकी </td>";
									}*/
									else if($desknm!='' && $test['desk_ltr_inword_no']=='')
									{
									
										echo "<td class='center'> देस्क्ने स्वीकारणे बाकी </td>";
									}
									echo "<td class='center'>".$dis_date."</font></td>";
									///////////////////////////////////////////////////////////////
									if($test['ltr_status']=='' || $test['ltr_status']=='closed')
									{
										echo "<td class='center'> कार्यवाही करणे बाकी </td>";
									}
									else
									{
										echo "<td class='center'>".$test['action_taken']."</td>";
									}
									
									echo "</tr>";
								}
								echo "</table></center>
								</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', 'Sandarbha-Nusar Report')" value="Export to Excel"></center>
							</p>
					</form>
                <br /><br />
                        <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php
}
##################################### End Of Desk Wise Report For Tapal #######################\################


############################ Desk Wise Report For BDO ##################################################
else if($no==3)
{
	include('dashboard_BDO.php');	
	?>
	<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 type="text/javascript">     
	var tableToExcel = (function() {
	var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
	return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
	}
	})()
	</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>
					<?php 
					$qryz=mysql_query("Select dept_nm from department_master where dept_id=(select dept_id from login where login_id='$username')");
					$rsz=mysql_fetch_array($qryz);
					
					$qry=mysql_query("Select desk_nm from desk_master where desk_id='$deskid' ");
					$rs=mysql_fetch_array($qry);
					?>
					<h1><?php echo 	$rsz['dept_nm'];?> डेस्क नुसार रिपोर्ट्स </h1>
				</div>
			</div><!--pageheader-->
			<div class="maincontent">
				<div class="maincontentinner">
					<h4 class="widgettitle"><?php echo 	$rsz['dept_nm'];?> डेस्क नुसार रिपोर्ट्स  (  <?php echo $rs['desk_nm'];?>  )    </h4>
					<form method="post" action="">
						<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>
						<?php 		
						####################################### Display Counter ###################################
						if($deskid=="" && $no==3)
							{
								convert_marathi();
								$qre=("SELECT tapal_to_dpt_transaction.desk_id, desk_master.desk_nm, COUNT(*) AS TOTAL FROM tapal_to_dpt_transaction,desk_master where tapal_to_dpt_transaction.desk_id=desk_master.desk_id GROUP BY desk_nm");
								$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>";
								while($rws = mysql_fetch_array($rsut))
									{
										$deptid=$rws['dept_id_from'];
										?>
										<tbody>
										<tr class="gradeX">
										<?php 
										echo "<td class='center'><a href='report_dpt_deskwise.php?deskid=$deskid&no=3'>".$rws['desk_nm']."</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> जतन प्रकारानुसार रिपोर्ट्स </h4></center></td></tr>";
							
							convert_marathi();
								$qre=("SELECT tapal_to_dpt_transaction.desk_id, desk_master.desk_nm, COUNT(*) AS TOTAL FROM tapal_to_dpt_transaction,desk_master where tapal_to_dpt_transaction.desk_id=desk_master.desk_id GROUP BY desk_nm");
								$rsut=mysql_query($qre) or die("".mysql_error());
								echo "
								<tr>
								<th>डेस्कचे नाव </th>
								<th>एकूण</th>
								</tr>";
								while($rws = mysql_fetch_array($rsut))
									{
										$deptid=$rws['dept_id_from'];
										echo "
										<tr>
										<td style='text-align:center;'>".$rws['desk_nm']."</td>
										<td style='text-align:center;'>". $rws['TOTAL']."</td> </tr>";      
									}
								echo "</table></div>";
			 			} 
							####################################### End Of Display Counter ########################
							############################### Display Details ###################################
							else if( $deskid != "" && $no==3)
							{
								convert_marathi();
								$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>';
									$id = $date1;
									$id1= $date2;
									$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction t, incoming_letters_transaction i, desk_transaction d
									WHERE i.ltr_id=t.ltr_id 
									AND d.dpt_ltr_id=t.dpt_ltr_id 
									AND d.desk_id_from='$deskid'") or die("sdfdfds".mysql_error());
									
								}
								else{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id = $date1;
									$id1= $date2;
									$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction t, incoming_letters_transaction i, desk_transaction d
									WHERE i.ltr_id=t.ltr_id 
									AND d.dpt_ltr_id=t.dpt_ltr_id 
									AND d.desk_id_from='$deskid' 
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
								}
									$count10=mysql_num_rows($result222);
									echo "<table id='dyntable' class='table table-bordered'>	
									<thead>
									<tr>
									<th class='head0 center'>पोलीस अधिक्षक कार्यालय<br>आवक_क्रमांक<br>आवक_दिनांक</th>
									<th class='head1 center'>संदर्भ <br>प्राप्त_दिनांक</th>
									<th class='head1 center'>विभाग<br>प्राप्त_दिनांक</th>
									<th class='head0 center'>विषय</th>
									<th class='head1 center'>कोणाकडून प्राप्त झाला</th> 
									<th class='head1 center'>डेस्कचा आवक_क्र  </th>
									<th class='head0 center'>डेस्कला प्राप्त_दि. </th>
									</tr>
									</thead>";
									while($test = mysql_fetch_array($result222))
									{
										$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
										$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
										if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
										{
											$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										//echo $dis_date;
										}
										else if($test['sent_to_desk_dt']!='')
										{
											$dis_date="--" ;			
										}
										$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$id1 = $test['ltr_inward_no'];
										$id2 = $test['assign_dept'];
										$id3 = $test['sandarbh_prakar'];
										$deskid=$test['desk_id'];
				
										echo "<tr class='gradeX'>
										<td class='center'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
										<td class='center'>".$test['ref_no']."</font><br>".$ref_date."</td>
										<td class='center'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>";
									/*	if($test['priority_days']=='0')
										{
											echo "<td class='center'>"."--"."</td>";
										}
										else if($test['priority_days']>'0')
										{
											echo "<td class='center'><a href=report_dpt_priority.php?id=$test[priority_days]&no=3>".$test['priority_days']."</a></td>";		
										}  */
										$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
										$rs09=mysql_query($qry09) or die("assssss".mysql_error());
										$rw09=mysql_fetch_array($rs09);
										$desknm=$rw09['desk_nm'];
										if($desknm!='')
										{
											echo "<td class='center'>".$test['desk_ltr_inword_no']."</td>";
										}
										else if($desknm=='')
										{
											echo "<td class='center'>डेस्क लावणे बाकी </td>";
										}
										echo "<td>".$dis_date."</font></td>
										</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> जतन प्रकारानुसार रिपोर्ट्स </h4></center></td></tr>";
								convert_marathi();
							if($date123==''&& $date223=='')
								{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id = $date1;
									$id1= $date2;
									$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction t, incoming_letters_transaction i, desk_transaction d
									WHERE i.ltr_id=t.ltr_id 
									AND d.dpt_ltr_id=t.dpt_ltr_id 
									AND d.desk_id_from='$deskid'") or die("sdfdfds".mysql_error());
									
								}
								else{
									echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
									$id = $date1;
									$id1= $date2;
									$result222=mysql_query("SELECT * FROM tapal_to_dpt_transaction t, incoming_letters_transaction i, desk_transaction d
									WHERE i.ltr_id=t.ltr_id 
									AND d.dpt_ltr_id=t.dpt_ltr_id 
									AND d.desk_id_from='$deskid' 
									AND (i.receive_dt BETWEEN '$date1' AND '$date2')") or die("sdfdfds".mysql_error());
								}
								$count10=mysql_num_rows($result222);
								echo "<tr>
								<th>पोलीस अधिक्षक कार्यालय<br>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ <br>प्राप्त_दिनांक</th>
								<th>विभाग<br>प्राप्त_दिनांक</th>
								<th>विषय</th>
								<th>कोणाकडून प्राप्त_झाला</th> 
								<th>डेस्कचा आवक_क्र  </th>
								<th>डेस्कला प्राप्त_दि. </th>
								</tr>
								</thead>";
								while($test = mysql_fetch_array($result222))
								{
									$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
									$rec_date 		= date('d-m-Y',strtotime($test['receive_dt']));
									if($test['sent_to_desk_dt']!='' && $test['sent_to_desk_dt']!=0)
									{
										$dis_date = date('d-m-Y',strtotime($test['sent_to_desk_dt']));
									//echo $dis_date;
									}
									else if($test['sent_to_desk_dt']!='')
									{
										$dis_date="--" ;			
									}
									$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
									$id1 = $test['ltr_inward_no'];
									$id2 = $test['assign_dept'];
									$id3 = $test['sandarbh_prakar'];
									$deskid=$test['desk_id'];
				
									echo "<tr>
									<td style='text-align:center;'>".$test['ltr_inword_no']."<br>".$rec_date ."</td>
									<td style='text-align:center;'>".$test['ref_no']."</font><br>".$ref_date."</td>
									<td style='text-align:center;'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
									<td style='text-align:center;'>".$test['subject']."</td>
									<td style='text-align:center;'>".$test['sender_name']."</td>";
								/*	if($test['priority_days']=='0')
									{
										echo "<td style='text-align:center;'>"."--"."</td>";
									}
									else if($test['priority_days']>'0')
									{
										echo "<td style='text-align:center;'>".$test['priority_days']."</td>";		
									} */
									$qry09="Select desk_nm from desk_master where desk_id='$deskid'";
									$rs09=mysql_query($qry09) or die("assssss".mysql_error());
									$rw09=mysql_fetch_array($rs09);
									$desknm=$rw09['desk_nm'];
									if($desknm!='')
									{
										echo "<td style='text-align:center;'>".$test['desk_ltr_inword_no']."</td>";
									}
									else if($desknm=='')
									{
										echo "<td style='text-align:center;'>डेस्क लावणे बाकी </td>";
									}
									echo "<td style='text-align:center;'>".$dis_date."</font></td>
									</tr>";
								}
								//mysql_close();
								echo"
								</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>
<?php
}
?>

