<!DOCTYPE html>

<?php
$flag=$_REQUEST['flag'];
//$id=$_REQUEST['id'];
if($flag=='')
{
	/*require_once('convert_marathi.php');
	$no=$_GET['no'];
	$ltrid=$_REQUEST['ltr_id'];*/
	$no=$_REQUEST['no'];

	if($no=='2') 
	{
		require_once('convert_marathi.php');
		//$no=$_GET['no'];
		$ltrid=$_REQUEST['ltr_id'];
		$no=$_REQUEST['no'];
		include('rec_sort_desk_dashboard.php');
		$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>
		function dt_check(str)
		{
			var dt  = document.getElementById(str);
			var dt1 = dt.value;
			if(dt1!="")
			{
			//alert("date chk"+dt1);
			
			var arr = dt1.split("-");
			var cnt = arr.length;
			//alert("cnt:"+cnt);
			
			if(cnt==3)
			{
				if(isNaN(arr[0]))
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
				else if(arr[0].length!=2)
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
				else if(parseInt(arr[0]) < 1 || parseInt(arr[0]) > 31)
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
				else if(isNaN(arr[1]))
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
				else if(arr[1].length!=2)
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
				else if(parseInt(arr[1]) < 1 || parseInt(arr[1]) > 12)
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
				else if(isNaN(arr[2]))
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
				else if(arr[2].length!=4)
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
				else if(parseInt(arr[2]) < 1970 || parseInt(arr[2]) > 2100)
				{
					alert("Please Enter Date in Proper Format!!!");
					//dt.focus();
					dt.value="";
					return false;
				}
			}
			else
			{
				alert("Please Enter Date in Proper Format!!!");
				dt.focus();
				dt.value="";
				return false;
			}
			
			}
		}
		</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());
							
							$id=$_REQUEST['id'];
							
							echo "<h4 class=widgettitle>".$rwx['desk_nm']." रेकॉर्ड सॉर्टिंग (  ".$id." )  </h4>";
							?>
							
							<form method="post" action="rec_sort_reportJatan.php?no=2&id=<?php echo $id; ?>&uname=<?php echo $username; ?>">
								<?php 		
								$id=$_REQUEST['id'];
								###################################### Display Counter ########################
								if($id=="")
								{
										convert_marathi(); 
										$qre=("SELECT d.vargawari, COUNT(*) AS TOTAL 
										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 
										WHERE ( d.vargawari!='' AND d.ltr_status !='')
										AND d.nasti_nashta_dt!='0000-00-00'
										AND d.desk_id_from=(select desk_id from login where login_id='$username')
										GROUP BY vargawari");
										
										$rsut=mysql_query($qre) or die("aaammm".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))
										{
											$id=$rws['vargawari'];
											?>
											<tbody>
											<tr class="gradeX">
											<?php 
											echo "<td class='center'><a href='rec_sort_reportJatan.php?no=2&id=$id'>".$rws['vargawari']."</a></td><td class='center'>". $rws['TOTAL']."</td> </tr>";       
										}
										?>
										</tbody>
										</table>
										<?php
										echo "<div id='divToPrint' style='display:none;'>
									<center><table id='export' border='1px' style='margin-left:50px;'>
									<tr><td colspan='9'><center><h4>". $rwx['desk_nm'] ." रेकॉर्ड सॉर्टिंग </h4></center></td></tr>";
									
									echo ' <center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2></center>';
										convert_marathi(); 
										$qre=("SELECT d.vargawari, COUNT(*) AS TOTAL 
										FROM desk_transaction d, tapal_to_dpt_transaction t, incoming_letters_transaction i
										WHERE ( d.vargawari!='' AND d.ltr_status !='')
										and d.dpt_ltr_id=t.dpt_ltr_id 
										AND i.ltr_id=t.ltr_id 
										AND d.nasti_nashta_dt!='0000-00-00'
										AND d.desk_id_from=(select desk_id from login where login_id='$username')
										GROUP BY vargawari");
										$rsut=mysql_query($qre) or die("".mysql_error());
										echo "<tr>
												<th>जतन प्रकार </th>
												<th>एकूण </th>
											</tr>";
										while($rws = mysql_fetch_array($rsut))
										{
											$id=$rws['vargawari'];
											echo "<tr>"; 
											echo "<td style='text-align:center;'>".$rws['vargawari']."</td><td style='text-align:center;'>". $rws['TOTAL']."</td></tr>";             
										}
										echo "</table></center></div>";
										
										echo "<br>
										<p>	
											<center>
												<input type='button' value='Print Page' onclick='PrintDiv();' class='btn btn-primary'/>
												<input type='button' class='btn' onclick='tableToExcel('sample_1', 'Sandarbha-Nusar Report')' value='Export to Excel'>
											</center>
										</p>";
							} 
							################################## End Of Display Counter #####################
							
							################################# Display Details  ########################################
							else if( $id!="")
							{
								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>";*/
									echo "<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=='')
									{
										convert_marathi();
										$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,de.nasti_nashta_dt
										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 (de.vargawari='$id' AND de.ltr_status!='')
										AND de.nasti_nashta_dt!='0000-00-00'
										AND de.desk_id_from=(select desk_id from login where login_id='$username') ") or die("sdfdfds".mysql_error());
									}
															
									echo "<table id='dyntable' class='table table-bordered'>
										<thead>
										<tr>
											<th class='head1 center'>विभाग आवक_क्रमांक<br>प्राप्त दिनांक</th>
											<th class='head0 center'>देस्क आवक_क्रमांक<br>व_आवक_दिनांक</th>
											<th class='head1 center'>विषय</th>
											<th class='head1 center'>कोणाकडून प्राप्त </th> 
											<th class='head1 center'>नस्‍ती	 सुरु कालावधी़ <br>( महिना / वर्ष )</th>
											<th class='head1 center'>नस्‍ती नष्‍ट करावयाचा कालावधी <br>( महिना / वर्ष )</th>
											<th class='head1 center'> केलेली कार्यवाही </th>
										</tr>
										</thead>
										<tbody>";
								$i=1;
								
								if($id!='अ')
								{
									while($test = mysql_fetch_array($result222))
									{
										$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
										$rec_date 		= date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
										$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										
										$d=$test['nasti_nashta_dt'];
										$exp=explode("-",$d);
										$nasti_dt=$exp[2]."-".$exp[1]."-".$exp[0];
										//$nasti_dt = date('d-m-Y',strtotime($test['nasti_nashta_dt']));
										
										$mnth1=  date('F',strtotime($test['dpt_ltr_rec_dt']));
										$yr1= date('Y',strtotime($test['dpt_ltr_rec_dt']));
										//echo $mnth;
										
										$mnth2=  date('F',strtotime($test['nasti_nashta_dt']));
										$yr2=$exp[0];
										
										
										echo "<tr class='gradeX'>
										<td style='text-align:center;'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
										<td style='text-align:center;'>".$test['desk_ltr_inword_no']."<br>".$rec_date."</td>		
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>
										<td class='center'>".$mnth1." / ".$yr1."</td>
										<td class='center'>".$mnth2." / ".$yr2."</td>
										<td class='center'>".$test['action_taken']."</td>";
										
										echo "</tr>";
										$i++;
									}
									//mysql_close();
								}
								else if($id=='अ')
								{
									while($test = mysql_fetch_array($result222))
									{
										$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
										$rec_date 		= date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
										$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										
										$d=$test['nasti_nashta_dt'];
										$exp=explode("-",$d);
										$nasti_dt=$exp[2]."-".$exp[1]."-".$exp[0];
										//$nasti_dt = date('d-m-Y',strtotime($test['nasti_nashta_dt']));
										
										$mnth1=  date('F',strtotime($test['dpt_ltr_rec_dt']));
										$yr1= date('Y',strtotime($test['dpt_ltr_rec_dt']));
										//echo $mnth;
										
										$mnth2=  date('F',strtotime($test['nasti_nashta_dt']));
										$yr2=$exp[0];
										
										
										echo "<tr class='gradeX'>
										<td style='text-align:center;'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
										<td style='text-align:center;'>".$test['desk_ltr_inword_no']."<br>".$rec_date."</td>		
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>
										<td class='center'>".$mnth1." / ".$yr1."</td>
										<td class='center'> कायम </td>
										<td class='center'>".$test['action_taken']."</td>";
										
										echo "</tr>";
										$i++;
									}
									//mysql_close();
								}
								echo"   </tbody>
									</table>";
									
								echo "<div id='divToPrint' style='display:none;'>
							<center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2>
							<table id='export' border='1px' style='margin-left:50px;'>";
								
							echo "<tr><td colspan='9'><center><b>".$rsz['dept_nm']."  रेकॉर्ड सॉर्टिंग </b></center></td></tr>";
							
							convert_marathi();
							$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,de.nasti_nashta_dt
							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 (de.vargawari='$id' AND de.ltr_status!='')
							AND de.nasti_nashta_dt!='0000-00-00'
							AND de.desk_id_from=(select desk_id from login where login_id='$username') ") or die("sdfdfds".mysql_error());
							
							echo "<tr>
									<th class='head1 center'>विभाग आवक_क्रमांक<br>प्राप्त दिनांक</th>
									<th class='head0 center'>देस्क आवक_क्रमांक<br>व_आवक_दिनांक</th>
									<th class='head1 center'>विषय</th>
									<th class='head1 center'>कोणाकडून प्राप्त </th> 
									<th class='head1 center'>नस्‍ती	 सुरु कालावधी़ <br>( महिना / वर्ष )</th>
									<th class='head1 center'>नसती नष्‍ट करावयाचा कालावधी <br>( महिना / वर्ष )</th>
									<th class='head1 center'> केलेली कार्यवाही </th>
								</tr>";
							$i=1;
								
								if($id!='अ')
								{
									while($test = mysql_fetch_array($result222))
									{
										$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
										$rec_date 		= date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
										$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										
										$d=$test['nasti_nashta_dt'];
										$exp=explode("-",$d);
										$nasti_dt=$exp[2]."-".$exp[1]."-".$exp[0];
										//$nasti_dt = date('d-m-Y',strtotime($test['nasti_nashta_dt']));
										
										$mnth1=  date('F',strtotime($test['dpt_ltr_rec_dt']));
										$yr1= date('Y',strtotime($test['dpt_ltr_rec_dt']));
										//echo $mnth;
										
										$mnth2=  date('F',strtotime($test['nasti_nashta_dt']));
										$yr2=$exp[0];
										
										
										echo "<tr class='gradeX'>
										<td style='text-align:center;'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
										<td style='text-align:center;'>".$test['desk_ltr_inword_no']."<br>".$rec_date."</td>		
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>
										<td class='center'>".$mnth1." / ".$yr1."</td>
										<td class='center'>".$mnth2." / ".$yr2."</td>
										<td class='center'>".$test['action_taken']."</td>";
										
										echo "</tr>";
										$i++;
									}
									//mysql_close();
								}
								else if($id=='अ')
								{
									while($test = mysql_fetch_array($result222))
									{
										$ref_date 		= date('d-m-Y',strtotime($test['ref_dt']));
										$rec_date 		= date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
										$dptrecdt=date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										
										$d=$test['nasti_nashta_dt'];
										$exp=explode("-",$d);
										$nasti_dt=$exp[2]."-".$exp[1]."-".$exp[0];
										//$nasti_dt = date('d-m-Y',strtotime($test['nasti_nashta_dt']));
										
										$mnth1=  date('F',strtotime($test['dpt_ltr_rec_dt']));
										$yr1= date('Y',strtotime($test['dpt_ltr_rec_dt']));
										//echo $mnth;
										
										$mnth2=  date('F',strtotime($test['nasti_nashta_dt']));
										$yr2=$exp[0];
										
										
										echo "<tr class='gradeX'>
										<td style='text-align:center;'>".$test['dpt_inword_no']."<br>".$dptrecdt."</td>
										<td style='text-align:center;'>".$test['desk_ltr_inword_no']."<br>".$rec_date."</td>		
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>
										<td class='center'>".$mnth1." / ".$yr1."</td>
										<td class='center'> कायम </td>
										<td class='center'>".$test['action_taken']."</td>";
										
										echo "</tr>";
										$i++;
									}
									//mysql_close();
								}
								echo" </table></div>";	
								
								
								
								echo "<br>
										<p>	
											<center>
												<input type='button' value='Print Page' onclick='PrintDiv();' class='btn btn-primary'/>
												<input type='button' class='btn' onclick='tableToExcel('sample_1', 'Sandarbha-Nusar Report')' value='Export to Excel'>
											</center>
										</p>";
								
						}
							
							###################### End Of Display Details  ###########################################
					?>		
					</form>
					<?php include_once('footer.php'); ?>
					</div><!--maincontentinner-->
				</div><!--maincontent-->
			</div><!--rightpanel-->
		</div><!--mainwrapper-->
		</body>
		</html>
<?php
	}

} // if($flag=='')

/////////////////////////////////////////////////////////////////////////////////////////////

else if($flag=='n')
{
	require_once('convert_marathi.php');
	$no=$_GET['no'];
	$ltrid=$_REQUEST['ltr_id'];

	######################################### Jatan Prakar Wise Report For Department ###############################

	include('rec_sort_dpt_dashboard.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);
				$id=$_REQUEST['id'];
				
				?>
               <!-- <h1><?php echo 	$rsz['dept_nm'];?> रेकॉर्ड सॉर्टिंग </h1>-->
				<h1> रेकॉर्ड सॉर्टिंग </h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
				<h4 class="widgettitle"><?php echo 	$rsz['dept_nm'];?> रेकॉर्ड सॉर्टिंग  ( <?php echo $id;?> ) </h4>
					<form method="post" action="rec_sort_reportJatan.php?flag=n&id=<?php echo $id; ?>&uname=<?php echo $username; ?>">
						<?php 		
							
							############################ Display Counter ##############################
							if($id=="" )
							{
								convert_marathi();
								$qre=("SELECT  t.vargawari, COUNT(*) AS TOTAL 
									FROM tapal_to_dpt_transaction t, incoming_letters_transaction i 
									WHERE  (t.vargawari!='' AND t.ltr_status!='')
									AND t.dept_id_from=(select dept_id from login where login_id='$username') 
									AND i.ltr_id=t.ltr_id 
									GROUP BY vargawari");
																 
								$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))
								{
									$id=$rws['vargawari'];
									?>
									<tbody>
									<tr class="gradeX">
									<?php 
									echo "<td class='center'><a href='rec_sort_reportJatan.php?flag=n&id=$id'>".$rws['vargawari']."</a></td><td class='center'>". $rws['TOTAL']."</td> </tr>";
								}
								echo "</tbody>
								</table>"; 
								
								
							echo "<div id='divToPrint' style='display:none;'>
							<center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2>
								<table id='export' border='1px' style='margin-left:50px;'>";
								
							echo "<tr><td colspan='9'><center><b>".$rsz['dept_nm']."  रेकॉर्ड सॉर्टिंग </b></center></td></tr>";
							echo "<tr>
									<th>जतन प्रकार </th>
									<th>एकूण </th>
								</tr>";
							convert_marathi();
							$qre=("SELECT  t.vargawari, COUNT(*) AS TOTAL 
									FROM tapal_to_dpt_transaction t, incoming_letters_transaction i 
									WHERE  (t.vargawari!='' AND t.ltr_status!='')
									AND t.dept_id_from=(select dept_id from login where login_id='$username') 
									AND i.ltr_id=t.ltr_id 
									GROUP BY vargawari");
																 
							$rsut=mysql_query($qre) or die("".mysql_error());	
							while($rws = mysql_fetch_array($rsut))
							{
								$id=$rws['vargawari'];
								?>
								<tbody>
								<tr class="gradeX">
								<?php 
								echo "<td class='center'><center>".$rws['vargawari']."</center></td><td class='center'><center>". $rws['TOTAL']."</center></td> </tr>";
							}	
							echo "</table></div>";	
							
							echo "<br>
							<p>	
								<center>
								<input type='button' value='Print Page' onclick='PrintDiv();' class='btn btn-primary'/>
								<input type='button' class='btn' onclick='tableToExcel('sample_1', 'Sandarbha-Nusar Report')' value='Export to Excel'></center>
							</p>";
						
						} 

						############################ End Of Display Counter ##############################	

						########################## Display Details ##################################
							else if( $id != "")
							{
								convert_marathi();
								$result222=mysql_query("SELECT * FROM incoming_letters_transaction i, 				tapal_to_dpt_transaction t
								where t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND ( t.vargawari='$id' AND t.ltr_status!='')
								AND i.ltr_id=t.ltr_id 	") or die("sdfdfds".mysql_error());
							
							echo " <table id='dyntable' class='table table-bordered'>	
								<thead>
									<tr>
										<th class='head1 center'>विभागीय आवक_क्र. <br>आवक_दिनांक </th>
										<th class='head1 center'>विषय</th>
										<th class='head1 center'>कोणाकडून प्राप्त </th> 
										<th class='head1 center'>नस्‍ती	 सुरु कालावधी़ (महिना/वर्ष) </th>
										<th class='head1 center'>नसती नष्‍ट करावयाचा कालावधी (महिना/वर्ष) </th>
										<th class='head1 center'> केलेली कार्यवाही </th>
									</tr>
								</thead>";
								$i=1;
								
								if($id !='अ')
								{	
									while($test = mysql_fetch_array($result222))
									{
										
										$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$ref_dt		= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrecdt=	date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$sent_dt		= date('d-m-Y',strtotime($test['sent_dt']));
										$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
										
										$d=$test['nasti_nashta_dt'];
										$exp=explode("-",$d);
										$nasti_dt=$exp[2]."-".$exp[1]."-".$exp[0];
										//$nasti_dt = date('d-m-Y',strtotime($test['nasti_nashta_dt']));
										
										$mnth1=  date('F',strtotime($test['dpt_ltr_rec_dt']));
										$yr1= date('Y',strtotime($test['dpt_ltr_rec_dt']));
										//echo $mnth;
										
										$mnth2=  date('F',strtotime($test['nasti_nashta_dt']));
										$yr2=$exp[0];
										
										echo "<tr class=gradeX>			
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>
										<td class='center'>".$mnth1." / ".$yr1."</td>
										<td class='center'>".$mnth2." / ".$yr2."</td> 
										<td class='center'>".$test['action_taken']."</td>";
										echo "</tr>";
										$i++;
									}
							}
							else if($id =='अ')
							{	
									while($test = mysql_fetch_array($result222))
									{
										
										$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$ref_dt		= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrecdt=	date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$sent_dt		= date('d-m-Y',strtotime($test['sent_dt']));
										$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
										
										$d=$test['nasti_nashta_dt'];
										$exp=explode("-",$d);
										$nasti_dt=$exp[2]."-".$exp[1]."-".$exp[0];
										//$nasti_dt = date('d-m-Y',strtotime($test['nasti_nashta_dt']));
										
										$mnth1=  date('F',strtotime($test['dpt_ltr_rec_dt']));
										$yr1= date('Y',strtotime($test['dpt_ltr_rec_dt']));
										//echo $mnth;
										
										$mnth2=  date('F',strtotime($test['nasti_nashta_dt']));
										$yr2=$exp[0];
										
										echo "<tr class=gradeX>			
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>
										<td class='center'>".$mnth1." / ".$yr1."</td>
										<td class='center'> कायम </td>
										<td class='center'>".$test['action_taken']."</td>";
										
										echo "</tr>";
										$i++;
									}
							}
								//mysql_close();
								echo"   </tbody>
								</table>";
							
							echo "<div id='divToPrint' style='display:none;'>
							<center><h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <h2>
								<table id='export' border='1px' style='margin-left:50px;'>";
								
							echo "<tr><td colspan='9'><center><b>".$rsz['dept_nm']."  रेकॉर्ड सॉर्टिंग </b></center></td></tr>";
							echo "<tr>
									<th class='head1 center'>विभागीय आवक_क्र. <br>आवक_दिनांक </th>
									<th class='head1 center'>विषय</th>
									<th class='head1 center'>कोणाकडून प्राप्त </th> 
									<th class='head1 center'>नस्‍ती	 सुरु कालावधी़ (महिना/वर्ष) </th>
									<th class='head1 center'>नसती नष्‍ट करावयाचा कालावधी (महिना/वर्ष) </th>
									<th class='head1 center'> केलेली कार्यवाही </th>
								</tr>";
							
								convert_marathi();
								$result222=mysql_query("SELECT * FROM incoming_letters_transaction i, 				tapal_to_dpt_transaction t
								where t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND ( t.vargawari='$id' AND t.ltr_status!='')
								AND i.ltr_id=t.ltr_id 	") or die("sdfdfds".mysql_error());
								
								$i=1;
								
								if($id !='अ')
								{	
									while($test = mysql_fetch_array($result222))
									{
										
										$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$ref_dt		= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrecdt=	date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$sent_dt		= date('d-m-Y',strtotime($test['sent_dt']));
										$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
										
										$d=$test['nasti_nashta_dt'];
										$exp=explode("-",$d);
										$nasti_dt=$exp[2]."-".$exp[1]."-".$exp[0];
										//$nasti_dt = date('d-m-Y',strtotime($test['nasti_nashta_dt']));
										
										$mnth1=  date('F',strtotime($test['dpt_ltr_rec_dt']));
										$yr1= date('Y',strtotime($test['dpt_ltr_rec_dt']));
										//echo $mnth;
										
										$mnth2=  date('F',strtotime($test['nasti_nashta_dt']));
										$yr2=$exp[0];
										
										echo "<tr class=gradeX>			
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>
										<td class='center'>".$mnth1." / ".$yr1."</td>
										<td class='center'>".$mnth2." / ".$yr2."</td> 
										<td class='center'>".$test['action_taken']."</td>";
										echo "</tr>";
										$i++;
									}
							}
							else if($id =='अ')
							{	
									while($test = mysql_fetch_array($result222))
									{
										
										$desk_ltr_rec_dt 	= date('d-m-Y',strtotime($test['desk_ltr_rec_dt']));
										$dept_rec_date 		= date('d-m-Y',strtotime($test['dpt_ltr_rec_dt']));
										$ref_dt		= date('d-m-Y',strtotime($test['ref_dt']));
										$deskrecdt=	date('d-m-Y',strtotime($test['sent_to_desk_dt']));
										$sent_dt		= date('d-m-Y',strtotime($test['sent_dt']));
										$rcv_dt		= date('d-m-Y',strtotime($test['receive_dt']));
										
										$d=$test['nasti_nashta_dt'];
										$exp=explode("-",$d);
										$nasti_dt=$exp[2]."-".$exp[1]."-".$exp[0];
										//$nasti_dt = date('d-m-Y',strtotime($test['nasti_nashta_dt']));
										
										$mnth1=  date('F',strtotime($test['dpt_ltr_rec_dt']));
										$yr1= date('Y',strtotime($test['dpt_ltr_rec_dt']));
										//echo $mnth;
										
										$mnth2=  date('F',strtotime($test['nasti_nashta_dt']));
										$yr2=$exp[0];
										
										echo "<tr class=gradeX>			
										<td class='center'>".$test['dpt_inword_no']."<br>".$dept_rec_date."</td>
										<td class='center'>".$test['subject']."</td>
										<td class='center'>".$test['sender_name']."</td>
										<td class='center'>".$mnth1." / ".$yr1."</td>
										<td class='center'> कायम </td>
										<td class='center'>".$test['action_taken']."</td>";
										
										echo "</tr>";
										$i++;
									}
							}
							//mysql_close();
								echo" </table> </div>";
							
							
							
							echo "<br>
							<p>	
								<center>
								<input type='button' value='Print Page' onclick='PrintDiv();' class='btn btn-primary'/>
								<input type='button' class='btn' onclick='tableToExcel('sample_1', 'Sandarbha-Nusar Report')' value='Export to Excel'></center>
							</p>";
							
						}
							########################## End Of Display Details ##################################
							?>
							
							
					</form>
					<br /><br />
                    <?php include_once('footer.php'); ?>
				</div><!--maincontentinner-->
			</div><!--maincontent-->
		</div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php 

######################################### End OF Jatan Prakar Wise Report For Department ########################

} //else if($flag=='n')
?>
