<?php
	ini_set('max_execution_time', 300);
	session_start();
	$username = $_SESSION['User_Name'];
	require_once('connection/db.php');
	require_once('convert_marathi.php');
	
	//to find desk_flag
	$qr=mysql_query("select dm.desk_flag from login l,department_master dm where l.login_id='$username' AND l.dept_id=dm.dept_id");
	$row=mysql_fetch_array($qr);
	$result=$row['desk_flag'];
	if($result=='y' || $result=='Y')
	{
		include_once('dashboard_department.php');
?>
<!DOCTYPE html>
<html>
	<head>
	<!-- Function for visible hidden effect-->
		<?php convert_marathi();	//display data in marathi
			$qry1 =("SELECT * FROM incoming_letters_transaction WHERE dept_id = (SELECT dept_id FROM login WHERE login_id ='$username') AND status!='approve' ORDER BY ltr_id DESC");
			$rs1=mysql_query($qry1);
			while($row1=mysql_fetch_array($rs1))
			{
				?>
				<script type="text/javascript">
				$(document).ready(function()
				{
					var ltr="<?php echo $row1['ltr_inword_no'];?>";
					$('#radiob'+ltr).fadeOut('fast');
					$('#dpts'+ltr).fadeOut('fast');
					$('#checkbox2'+ltr).change(function()
						{
						if($(this).is(':checked'))
							{
								$('#checkbox1'+ltr).attr('disabled',true);
								$('#radiob'+ltr).fadeIn('slow');
							}
						else
							{
								$('#radiob'+ltr).fadeOut('slow');
								$('#dpts'+ltr).fadeOut('slow');
								$('#checkbox1'+ltr).attr('disabled',false);
							}
						});
					$('#othdpt'+ltr).change(function()
						{
							if(this.checked)
								{
									alert("ddddd");
									$('#dpts'+ltr).fadeIn('slow');
								}
							else
								{
									$('#dpts'+ltr).fadeIn('slow');
								}
						});
					$('#tpl'+ltr).change(function()
						{
							if(this.checked)
								{
									$('#dpts'+ltr).fadeIn('slow');
								}
							else
								{
									$('#dpts'+ltr).fadeOut('slow');
								}
						});

					$('#checkbox1'+ltr).change(function()
						{
							if(this.checked)
								{
									$('#checkbox2'+ltr).attr('disabled',true);
									$('#radiob'+ltr).fadeOut('slow');
									$('#dpts'+ltr).fadeOut('slow');
								}
							else
								{
									$('#checkbox2'+ltr).attr('disabled',false);
								}
						});
				})
			</script>
		<?php  } ?>
		</head>
		<body>
			<div class="rightpanel">
				<ul class="breadcrumbs">
					<li><a href="dashboard_department.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
					<li><a href="dashboard_department.php">Tables</a> <span class="separator"></span></li>
					<li>पत्राचा स्वीकार करा</li>
				</ul>
				<div class="pageheader">
					<div class="pageicon"><span class="iconfa-table"></span></div>
					<div class="pagetitle">
						<h5>Tables</h5>
						<h1>पत्राचा स्वीकार करा</h1>
					</div>
				</div><!--pageheader-->
        
				<div class="maincontent">
					<div class="maincontentinner">
						<?php
						
							convert_marathi();
							$qrye =("SELECT * FROM incoming_letters_transaction WHERE dept_id = (SELECT dept_id FROM login WHERE login_id ='$username') AND status!='approve' ORDER BY ltr_id DESC LIMIT 200 ");
							$rsult=mysql_query($qrye) or die("vvvv".mysql_error());
							 while($rw=mysql_fetch_array($rsult))	 
							{	
								$status=$rw['status'];
								$year = date('y');
								//create dpt unique inword no
								$dpt=$rw['dept_id'];
								$id=$rw['ltr_id'];	
								$year = date('y');
								//echo $year;
								
								$r = mysql_query("select max(t.dpt_inword_no) as id from tapal_to_dpt_transaction t, incoming_letters_transaction i
								where  t.dpt_inword_no like '$year%' 
								AND t.dept_id_from=(SELECT dept_id from login where login_id = '$username')
								AND t.ltr_id=i.ltr_id ") ;
								$row1 = mysql_fetch_array($r);
								$Auto_increment = $row1['id'];
								$start='0001';
								################################################################################
												// Generating Inward No
								################################################################################
								if ($Auto_increment != '')
								{	
									list($a,$b) = Explode("-",$Auto_increment);
									if ($a==$year)
									{
										$c= str_pad($b + 1, 4, 0, STR_PAD_LEFT);
										$n = $year ."-". $c;
									}
									else
									{
										$c= str_pad($b + 1, 4, 0, STR_PAD_LEFT);
										$n =  $year."-". $c;
									}
								}
								else
								{
									$n =$year."-". $start;
								}
								
								$dt=$rw['sent_dt'];
								##############################################################################
													//Allocating Status as approve 
								###############################################################################
								if(isset($_POST['allocate_status' . $rw['ltr_inword_no']]))
									{
										$selectedoption = $_POST['allocate_status' . $rw['ltr_inword_no']];
										$nuk=$rw['ltr_id'];
										$ltrid=$rw['ltr_id'];
										//echo $nuk;
										$sqlt=("SELECT * FROM incoming_letters_transaction where dept_id!='0' AND status!='approve'");
										$rwlt=mysql_query($sqlt) or die("cxcdfd".mysql_error());
										$sqlt=("SELECT * FROM tapal_to_dpt_transaction t, incoming_letters_transaction i 
										where t.ltr_id=i.ltr_id 
										AND i.status!='approve'
										AND i.status!='closed' 
										AND i.ltr_inword_no='$nuk'
										AND (t.status!='approve')");
										$rwlt=mysql_query($sqlt) or die("cxcdfd".mysql_error());
										$count=mysql_num_rows($rwlt);
										while($df=mysql_fetch_array($rwlt))
											{
												$dpt=$df['dept_id'];
											}

										if($selectedoption==('approve'.$rwlt['ltr_inword_no']))
										{	
											   $sql1 = ("INSERT into tapal_to_dpt_transaction (dpt_inword_no, dpt_ltr_rec_dt, dpt_ltr_aprv_dt, status, dept_id_from, ltr_id) VALUES('$n', '$dt', curdate(), 'approve', '$dpt', '$id')");
											   if(mysql_query($sql1))
											   {
													$sql2=("UPDATE incoming_letters_transaction SET status='approve' ,dpt_inword_no='$n' WHERE ltr_id='$ltrid'");
													if(mysql_query($sql2))
													{
														echo "<script type='text/javascript'>alert('Approved Successfully!')</script>";
														echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
													}
													else
													{
														
														echo "<script type='text/javascript'>alert('Approve Unsuccessful!')</script>";
														echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';	
														
													}
												}
												else
												{
													echo "<script type='text/javascript'>alert('Unable to insert Record!.. ')</script>";
													echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
												}
												
										}	
									}
									
										/***************************************************************
																return coding	
										*****************************************************************/
									if($selectedoption=='return')
										{	
											$rtnchoice=$_POST['choice'];
											$rtntodpt = $_POST['departmentnm' . $rw['ltr_id']];
											if( ($rtntodpt!='' && $rtnchoice=='Department') || ($rtnchoice=='Tapal' && $rtntodpt==''))
											{	
												$ltrinwardno=$rw['ltr_inword_no'];
												$rtn_from=$rw['dept_id'];
												$sentdate = strtotime($rw['sent_dt']);
												$sndt= date('Y-m-d', $sentdate);
												
												//$sql2=("UPDATE incoming_letters_transaction SET status='returned', dept_id='0' WHERE ltr_id='$rw[ltr_id]'");
												convert_marathi();
												$qry1=("INSERT INTO returned_from_dpt(ltr_inword_no, ltr_rec_dt, dpt_rtn_dt, rtn_choice, rtn_from, assign_to) VALUES('$ltrinwardno','$sndt' , curdate(),'$rtnchoice','$rtn_from', '$rtntodpt')") or die("mmmm".mysql_error());
												if($rtntodpt!='0')
												{
													$qry2=("UPDATE incoming_letters_transaction SET dept_id='$rtntodpt', rtn_choice='$rtnchoice', status='pending' WHERE ltr_id='$id' ");
												
												}
												else
												{
												//echo "<br>aaaa2";
													$qry2=("UPDATE incoming_letters_transaction SET dept_id='0', rtn_choice='$rtnchoice', status='pending' WHERE ltr_id='$id' ");	
												}
												
												if(mysql_query($qry1))
												{  
													mysql_query($qry2);
													echo "<script type='text/javascript'>alert('Returned Successfully!')</script>";
													echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
												}	
												else
												{   
													echo "<script type='text/javascript'>alert('Returned Unsuccessful!')</script>";
													echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
													if($rtntodpt!='0')
													{
														$qry2=mysql_query("UPDATE incoming_letters_transaction SET dept_id='$dptid', rtn_choice='', status='pending' WHERE ltr_id='$id' ");
												
													}
													else
													{
														//echo "<br>aaaa2";
														$qry2=mysql_query("UPDATE incoming_letters_transaction SET dept_id='0', rtn_choice='', status='pending' WHERE ltr_id='$id' ");	
													}
												}
											}
											else
											{
													echo "<script type='text/javascript'>alert('कृपया पत्र परत करण्यासाठीची माहिती भरा!')</script>";
													echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
											}
										}
							}
						//while
				?>
							<h4 class="widgettitle">पत्राचा स्वीकार करा</h4>
								<form action="acceptletter.php" method="post">
									<table id="dyntable" class="table table-bordered">
									<thead>
									<tr>
										<th class="head0 center">पोलीस अधिक्षक <br>कार्यालय <br>आवक_क्रमांक /दिनांक   </th>
										<th class="head1 center">संदर्भ_क्रमांक /संदर्भ_दिनांक</th>
										<th class="head0 center">विभागीय प्राप्त_दिनांक</th>
										<th class="head1 center">कोणाकडून प्राप्त झाले  </th>
										<th class="head0 center">थोडक्यात विषय</th>
										<th class="head1 center">संदर्भाचा प्रकार</th>
										<th class="head0 center">View Document</th>
										<th class="head0 center">स्वीकृत करा</th>
										<th class="head1 center">परत करा</th>
									</tr>
									</thead>
									<tbody>
									<?php 
									#########################################################################################
											//Fetching All Data In Datatable
									#########################################################################################
									convert_marathi();	//display data in marathi
									$qry1 =("SELECT * FROM incoming_letters_transaction WHERE dept_id = (SELECT dept_id FROM login WHERE login_id ='$username') AND status!='approve' ORDER BY ltr_id DESC LIMIT 200 ");
					
									$rs1=mysql_query($qry1);
									while($row1=mysql_fetch_array($rs1))
										{
											$refdate = strtotime($row1['ref_dt']);
											$ref= date('d-m-Y', $refdate);
											//sent_dt
											$sentdate = strtotime($row1['sent_dt']);
											$sdt= date('d-m-Y', $sentdate);
											$rcv_dt		= date('d-m-Y',strtotime($row1['receive_dt']));
									?>
											<tr>
											<td class="center"><?php echo $row1['ltr_inword_no']."<br>".$rcv_dt;
											$id=$row1['ltr_inword_no']; ?></td>
											<td class="center"><?php echo $row1['ref_no']."<br>".$ref;?></td>
											<td class="center"><?php echo $sdt;?></td>
											<td class="center"><?php echo $row1['sender_name'];?></td>
											<td class="center"><?php echo $row1['subject'];?></td>
											<?php
												convert_marathi();
												$qry5=("Select * from sandharbh_master,incoming_letters_transaction WHERE sandharbh_master.sandhrbh_id=incoming_letters_transaction.ltr_type AND incoming_letters_transaction.ltr_inword_no='$id'");
												$rs5=mysql_query($qry5) or die ("mmmm". mysql_error());
												while($rw5=mysql_fetch_array($rs5))
													{
														$ltr=$rw5['sandharbh_nm'];
													}
											?>
											<td class="center"><?php echo $ltr; ?></td>	
											<td class="center"><a href="view_avak.php?user=1&ltrid=<?php echo $row1['ltr_id'];?>">View</a></td>	
											<td class="center" style="width:110px;">
											<?php  
											echo "  		
												<label><input type='checkbox' name='allocate_status". $row1['ltr_inword_no']."' id='checkbox1".$row1['ltr_inword_no']."' value='approve' > स्वीकृत करा</label></td>
												<td>  <label style=width:110px;><input  type='checkbox' name='allocate_status". $row1['ltr_inword_no']."'  value='return' id='checkbox2". $row1['ltr_inword_no']."' >  परत करा</label>"; 
											echo "<div id='radiob". $row1['ltr_inword_no']."'>
												<div id='tpl". $row1['ltr_inword_no']."'><label><input type=radio name='choice' id='status' value='Tapal'>टपाल</label></div><div id='othdpt". $row1['ltr_inword_no'] ."'><label><input type=radio name='choice' id='status' value='Department'> विभागास </label></div></div>";		
											echo "<div id='dpts". $row1['ltr_inword_no']."'><select name='departmentnm".$row1['ltr_id']."'>Dropdown</option><option value=> विभाग निवडा </option>";
											$qr=mysql_query("Select * from department_master where dept_id!=(select dept_id from login where login_id='$username')");
											while($row = mysql_fetch_array($qr))
												{
													echo"	{
													('<option id='".$row['dept_id']."' value='".$row['dept_id']."'>".$row['dept_nm']."</option>')
												}";
												}
											echo" </select></div></td></tr>";
										} //while
											?>
										</tbody>
									</table><br>
										<p class="stdformbutton">
											<center>
												<button class="btn btn-primary" onclick="return validateStampPurchase()" name="ok" value="ok">बदल करा </button>
												<button type="reset" class="btn">रद्द करा </button>
											</center>
										</p>
									<br /><br />
								</form> 
                
							<?php   
								include_once('footer.php');
								?>
						</div><!--maincontentinner-->
				</div><!--maincontent-->
			</div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php
}// end if(flag=y)
	
else if($result=='n' || $result=='N')
{
include_once('new_dashboard_department.php');
?>
<!DOCTYPE html>
<html>
	<head>
	
	<!-- Function for visible hidden effect-->
		<?php convert_marathi();	//display data in marathi
			$qry1 =("SELECT * FROM incoming_letters_transaction WHERE dept_id = (SELECT dept_id FROM login WHERE login_id ='$username') AND status!='approve' ORDER BY ltr_id DESC");
			$rs1=mysql_query($qry1);
			while($row1=mysql_fetch_array($rs1))
			{
				?>
				<script type="text/javascript">
				$(document).ready(function()
				{
					var ltr="<?php echo $row1['ltr_inword_no']; ?>";
					$('#radiob'+ltr).fadeOut('fast');
					$('#dpts'+ltr).fadeOut('fast');
					$('#checkbox2'+ltr).change(function()
						{
						if($(this).is(':checked'))
							{
								$('#checkbox1'+ltr).attr('disabled',true);
								$('#radiob'+ltr).fadeIn('slow');
							}
						else
							{
								$('#radiob'+ltr).fadeOut('slow');
								$('#dpts'+ltr).fadeOut('slow');
								$('#checkbox1'+ltr).attr('disabled',false);
							}
						});
					$('#othdpt'+ltr).change(function()
						{
							if(this.checked)
								{
									alert("ddddd");
									$('#dpts'+ltr).fadeIn('slow');
								}
							else
								{
									$('#dpts'+ltr).fadeIn('slow');
								}
						});
					$('#tpl'+ltr).change(function()
						{
							if(this.checked)
								{
									$('#dpts'+ltr).fadeIn('slow');
								}
							else
								{
									$('#dpts'+ltr).fadeOut('slow');
								}
						});

					$('#checkbox1'+ltr).change(function()
						{
							if(this.checked)
								{
									$('#checkbox2'+ltr).attr('disabled',true);
									$('#radiob'+ltr).fadeOut('slow');
									$('#dpts'+ltr).fadeOut('slow');
								}
							else
								{
									$('#checkbox2'+ltr).attr('disabled',false);
								}
						});
				})
			</script>
		<?php  } ?>
		
		<link type="text/css" rel="stylesheet" href="style2.css" />
		
		</head>
		<body onload="fun()">
			<div class="rightpanel">
				<ul class="breadcrumbs">
					<li><a href="dashboard_department.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
					<li><a href="dashboard_department.php">Tables</a> <span class="separator"></span></li>
					<li>पत्राचा स्वीकार करा</li>
				</ul>
				<div class="pageheader">
					<div class="pageicon"><span class="iconfa-table"></span></div>
					<div class="pagetitle">
						<h5>Tables</h5>
						<h1>पत्राचा स्वीकार करा</h1>
					</div>
				</div><!--pageheader-->
        
				<div class="maincontent">
					<div class="maincontentinner">
						<?php
							convert_marathi();
							$qrye =("SELECT * FROM incoming_letters_transaction WHERE dept_id = (SELECT dept_id FROM login WHERE login_id ='$username') AND status!='approve'");
							$rsult=mysql_query($qrye) or die("vvvv".mysql_error());
							 while($rw=mysql_fetch_array($rsult))	 
							{	
								$status=$rw['status'];
								$year = date('y');
								//create dpt unique inword no
								$dpt=$rw['dept_id'];
								$id=$rw['ltr_id'];	
								$year = date('y');
								//echo $year;
								$r = mysql_query("select max(tapal_to_dpt_transaction.dpt_inword_no) as id from tapal_to_dpt_transaction, incoming_letters_transaction where  tapal_to_dpt_transaction.dpt_inword_no like '$year%' AND tapal_to_dpt_transaction.dept_id_from=(SELECT dept_id from login where login_id = '$username') AND tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id ") ;
								$row1 = mysql_fetch_array($r);
								$Auto_increment = $row1['id'];
								$start='0001';
								################################################################################
												// Generating Inward No
								################################################################################
								if ($Auto_increment != '')
									{	
										list($a,$b) = Explode("-",$Auto_increment);
										if ($a==$year)
											{
												$c= str_pad($b + 1, 4, 0, STR_PAD_LEFT);
												$n = $year ."-". $c;
											}
										else
											{
												$c= str_pad($b + 1, 4, 0, STR_PAD_LEFT);
												$n =  $year."-". $c;
											}
									}
								else
									{
										$n =$year."-". $start;
									}
								$dt=$rw['sent_dt'];
								##############################################################################
													//Allocating Status as approve 
								###############################################################################
								if(isset($_POST['allocate_status' . $rw['ltr_inword_no']]))
									{
										$selectedoption = $_POST['allocate_status' . $rw['ltr_inword_no']];
										$nuk=$rw['ltr_id'];
										$ltrid=$rw['ltr_id'];
										//echo $nuk;
										$sqlt=("SELECT * FROM incoming_letters_transaction where dept_id!='0' AND status!='approve'");
										$rwlt=mysql_query($sqlt) or die("cxcdfd".mysql_error());
										$sqlt=("SELECT * FROM tapal_to_dpt_transaction, incoming_letters_transaction where tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id AND incoming_letters_transaction.status!='approve' AND incoming_letters_transaction.status!='closed' AND incoming_letters_transaction.ltr_inword_no='$nuk' and (tapal_to_dpt_transaction.status!='approve')");
										$rwlt=mysql_query($sqlt) or die("cxcdfd".mysql_error());
										$count=mysql_num_rows($rwlt);
										while($df=mysql_fetch_array($rwlt))
											{
												$dpt=$df['dept_id'];
											}

										if($selectedoption==('approve'.$rwlt['ltr_inword_no']))
										{	
											   $sql1 = ("INSERT into tapal_to_dpt_transaction (dpt_inword_no, dpt_ltr_rec_dt, dpt_ltr_aprv_dt, status, dept_id_from, ltr_id) VALUES('$n', '$dt', curdate(), 'approve', '$dpt', '$id')");
											   if(mysql_query($sql1))
											   {
													$sql2=("UPDATE incoming_letters_transaction SET status='approve' ,dpt_inword_no='$n' WHERE ltr_id='$ltrid'");
													if(mysql_query($sql2))
													{
														echo "<script type='text/javascript'>alert('Approved Successfully!')</script>";
														echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
													}
													else
													{
														
														echo "<script type='text/javascript'>alert('Approve Unsuccessful!')</script>";
														echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';	
														
													}
												}
												else
												{
													echo "<script type='text/javascript'>alert('Unable to insert Record!.. ')</script>";
													echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
												}
												
										}	
									}
									
										/***************************************************************
																return coding	
										*****************************************************************/
									if($selectedoption=='return')
										{	
											$rtnchoice=$_POST['choice'];
											$rtntodpt = $_POST['departmentnm' . $rw['ltr_id']];
											if( ($rtntodpt!='' && $rtnchoice=='Department') || ($rtnchoice=='Tapal' && $rtntodpt==''))
											{	
												$ltrinwardno=$rw['ltr_inword_no'];
												$rtn_from=$rw['dept_id'];
												$sentdate = strtotime($rw['sent_dt']);
												$sndt= date('Y-m-d', $sentdate);
												
												//$sql2=("UPDATE incoming_letters_transaction SET status='returned', dept_id='0' WHERE ltr_id='$rw[ltr_id]'");
												convert_marathi();
												$qry1=("INSERT INTO returned_from_dpt(ltr_inword_no, ltr_rec_dt, dpt_rtn_dt, rtn_choice, rtn_from, assign_to) VALUES('$ltrinwardno','$sndt' , curdate(),'$rtnchoice','$rtn_from', '$rtntodpt')") or die("mmmm".mysql_error());
												if($rtntodpt!='0')
												{
													$qry2=("UPDATE incoming_letters_transaction SET dept_id='$rtntodpt', rtn_choice='$rtnchoice', status='pending' WHERE ltr_id='$id' ");
												
												}
												else
												{
												//echo "<br>aaaa2";
													$qry2=("UPDATE incoming_letters_transaction SET dept_id='0', rtn_choice='$rtnchoice', status='pending' WHERE ltr_id='$id' ");	
												}
												
												if(mysql_query($qry1))
												{  
													mysql_query($qry2);
													echo "<script type='text/javascript'>alert('Returned Successfully!')</script>";
													echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
												}	
												else
												{   
													echo "<script type='text/javascript'>alert('Returned Unsuccessful!')</script>";
													echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
													if($rtntodpt!='0')
													{
														$qry2=mysql_query("UPDATE incoming_letters_transaction SET dept_id='$dptid', rtn_choice='', status='pending' WHERE ltr_id='$id' ");
												
													}
													else
													{
														//echo "<br>aaaa2";
														$qry2=mysql_query("UPDATE incoming_letters_transaction SET dept_id='0', rtn_choice='', status='pending' WHERE ltr_id='$id' ");	
													}
												}
											}
											else
											{
													echo "<script type='text/javascript'>alert('कृपया पत्र परत करण्यासाठीची माहिती भरा!')</script>";
													echo '<script language="JavaScript"> window.location.href ="acceptletter.php" </script>';
											}
										}
							}	//while
				?>
				
				
				
							<h4 class="widgettitle">पत्राचा स्वीकार करा</h4>
								<form action="acceptletter.php" method="post">
								
								
							<!--############################### POPUP CODE ###################################-->

							<div id="overlay"></div>
							<div id="popup" style=" width:600px;overflow-y:scroll;overflow-x:scroll;">
								<div class="popupcontrols popupHeader" >
									<span class="header_title"> अलर्ट </span>
									<span id="popupclose">X</span>
								</div>
								<div class="popupcontent">
									<div id="parent">
										
										<center>	
										<table style="width:450px;">
                       <?php 
						
						
						//accepted by dept but nt taken ny action
						$result = mysql_query("SELECT t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, i.priority_days, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON ( di.ltr_id = t.ltr_id AND di.desk_ltr_id='0')
						WHERE t.ltr_status='' AND t.returned_choice=''
						AND t.dept_id_from = ( SELECT dept_id from login where login_id = '$username' )") or die("cccc".mysql_error());
						
						$n1=mysql_num_rows($result);
						
						//not accepted by dept
						$result1 = mysql_query("SELECT t.action_taken, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, t.update_date, t.dispatched_date, t.status, di.addressed_to, t.ltr_status, i.sender_name, i.ltr_id, i.priority_days, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, t.scan_doc, di.outword_no, di.dispatched_to, t.ltr_category, t.assign_no 
						FROM incoming_letters_transaction i LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id 
						LEFT OUTER JOIN dispatched_transaction di ON ( di.ltr_id = t.ltr_id AND di.desk_ltr_id='0')
						WHERE i.status='pending' 
						AND i.dept_id = (SELECT dept_id from login where login_id = '$username')") or die("cccc2".mysql_error());
						
						$n2=mysql_num_rows($result1);
						
						if($n1!=0 || $n2!=0)
						{
								
								echo "<tr><td> &nbsp&nbsp&nbsp&nbsp <b> आवक_क्र. </b></td>
										<td>&nbsp&nbsp&nbsp&nbsp <b> संदर्भ_क्र. </b></td>
										<td>&nbsp&nbsp&nbsp&nbsp <b> विषय </b></td>
										<td>&nbsp&nbsp&nbsp&nbsp <b> पत्राची स्थिती </b></td>
										<td>&nbsp&nbsp&nbsp&nbsp <b> मुदत </b></td></tr>
										<tr><td colspan=3>&nbsp;</td></tr>";
								
								
								while($row=mysql_fetch_array($result))
								{ 
									$priority_days=$row['priority_days'];
									$receive_dt	=strtotime($row['receive_dt']);

									$to_dt=strtotime("+".$priority_days." days",$receive_dt);
									//echo date("d-m-Y",$to_dt)."aa";
									
									$frm_dt=strtotime("-2 days",$to_dt);
									if(strtotime($date123)>=$frm_dt && strtotime($date123)<=$to_dt)
									{
										echo "<tr style=height:20px;>
											<td style=height:18px;>&nbsp&nbsp&nbsp&nbsp".$row['ltr_inword_no']."</td>
											<td>&nbsp&nbsp&nbsp&nbsp".$row['ref_no']."</td>
											<td style=height:18px;>&nbsp&nbsp&nbsp&nbsp".$row['subject']."</td>
											<td>&nbsp&nbsp&nbsp&nbsp विभागाने कार्यवाही करणे बाकी </td>
											<td> &nbsp&nbsp&nbsp&nbsp ".date('d-m-Y',$to_dt)." </td>
										</tr>";
									}
								}
								
								
								
								while($row=mysql_fetch_array($result1))
								{ 
									$priority_days=$row['priority_days'];
									$receive_dt	=strtotime($row['receive_dt']);

									$to_dt=strtotime("+".$priority_days." days",$receive_dt);
									//echo date("d-m-Y",$to_dt)."aa";
									
									$frm_dt=strtotime("-2 days",$to_dt);
									if(strtotime($date123)>=$frm_dt && strtotime($date123)<=$to_dt)
									{
										echo "<tr style=height:20px;>
											<td style=height:18px;>&nbsp&nbsp&nbsp&nbsp".$row['ltr_inword_no']."</td>
											<td>&nbsp&nbsp&nbsp&nbsp".$row['ref_no']."</td>
											<td style=height:18px;>&nbsp&nbsp&nbsp&nbsp".$row['subject']."</td>
											<td>&nbsp&nbsp&nbsp&nbsp विभागाने स्वीकारणे बाकी </td>
											<td> &nbsp&nbsp&nbsp&nbsp ".date('d-m-Y',$to_dt)." </td>
										</tr>";
									}
									
								}
						}
						else
						{
							echo "<h3> No records found....</h3>";
						}
						
						
						
						?>
						</table>
									</center>
									
									</div>
								</div>
							</div>

			<!--##################################################################-->		
								
								
									<table id="dyntable" class="table table-bordered">
									<thead>
									<tr>
										<th class="head0 center">पोलीस अधिक्षक <br>कार्यालय <br>आवक_क्रमांक /दिनांक   </th>
										<th class="head1 center">संदर्भ_क्रमांक /संदर्भ_दिनांक</th>
										<th class="head0 center">विभागीय प्राप्त_दिनांक</th>
										<th class="head1 center">कोणाकडून प्राप्त झाले  </th>
										<th class="head0 center">थोडक्यात विषय</th>
										<th class="head1 center">संदर्भाचा प्रकार</th>
										<th class="head0 center">View Document</th>
										<th class="head0 center">स्वीकृत करा</th>
										<th class="head1 center">परत करा</th>
									</tr>
									</thead>
									<tbody>
									<?php 
									#########################################################################################
											//Fetching All Data In Datatable
									#########################################################################################
									convert_marathi();	//display data in marathi
									$qry1 =("SELECT * FROM incoming_letters_transaction WHERE dept_id = (SELECT dept_id FROM login WHERE login_id ='$username') AND status!='approve' ORDER BY ltr_id DESC");
					
									$rs1=mysql_query($qry1);
									while($row1=mysql_fetch_array($rs1))
										{
											$refdate = strtotime($row1['ref_dt']);
											$ref= date('d-m-Y', $refdate);
											//sent_dt
											$sentdate = strtotime($row1['sent_dt']);
											$sdt= date('d-m-Y', $sentdate);
											$rcv_dt		= date('d-m-Y',strtotime($row1['receive_dt']));
									?>
											<tr>
											<td class="center"><?php echo $row1['ltr_inword_no']."<br>".$rcv_dt;
											$id=$row1['ltr_inword_no']; ?></td>
											<td class="center"><?php echo $row1['ref_no']."<br>".$ref;?></td>
											<td class="center"><?php echo $sdt;?></td>
											<td class="center"><?php echo $row1['sender_name'];?></td>
											<td class="center"><?php echo $row1['subject'];?></td>
											<?php
												convert_marathi();
												$qry5=("Select * from sandharbh_master,incoming_letters_transaction WHERE sandharbh_master.sandhrbh_id=incoming_letters_transaction.ltr_type AND incoming_letters_transaction.ltr_inword_no='$id'");
												$rs5=mysql_query($qry5) or die ("mmmm". mysql_error());
												while($rw5=mysql_fetch_array($rs5))
													{
														$ltr=$rw5['sandharbh_nm'];
													}
											?>
											<td class="center"><?php echo $ltr; ?></td>	
											<td class="center"><a href="view_avak.php?flag=n&user=1&ltrid=<?php echo $row1['ltr_id'];?>">View</a></td>
											<td class="center" style="width:110px;">
											<?php  
											echo "  		
												<label><input type='checkbox' name='allocate_status". $row1['ltr_inword_no']."' id='checkbox1".$row1['ltr_inword_no']."' value='approve' > स्वीकृत करा</label></td>
												<td>  <label style=width:110px;><input  type='checkbox' name='allocate_status". $row1['ltr_inword_no']."'  value='return' id='checkbox2". $row1['ltr_inword_no']."' >  परत करा</label>"; 
											echo "<div id='radiob". $row1['ltr_inword_no']."'>
												<div id='tpl". $row1['ltr_inword_no']."'><label><input type=radio name='choice' id='status' value='Tapal'>टपाल</label></div><div id='othdpt". $row1['ltr_inword_no'] ."'><label><input type=radio name='choice' id='status' value='Department'> विभागास </label></div></div>";		
											echo "<div id='dpts". $row1['ltr_inword_no']."'><select name='departmentnm".$row1['ltr_id']."'>Dropdown</option><option value=> विभाग निवडा </option>";
											$qr=mysql_query("Select * from department_master where dept_id!=(select dept_id from login where login_id='$username')");
											while($row = mysql_fetch_array($qr))
												{
													echo"	{
													('<option id='".$row['dept_id']."' value='".$row['dept_id']."'>".$row['dept_nm']."</option>')
												}";
												}
											echo" </select></div></td></tr>";
										} //while
											?>
										</tbody>
									</table><br>
										<p class="stdformbutton">
											<center>
												<button class="btn btn-primary" onclick="return validateStampPurchase()">बदल करा </button>
												<button type="reset" class="btn">रद्द करा </button>
											</center>
										</p>
									<br /><br />
								</form> 
                
				
							 <script>

		function fun()
		{

			// Initialize Variables
			var closePopup = document.getElementById("popupclose");
			
			var overlay = document.getElementById("overlay");
			var popup = document.getElementById("popup");
			var button = document.getElementById("button");
		   
			// Show Overlay and Popup

				overlay.style.display = 'block';
				popup.style.display = 'block';

		}

		


		  // Initialize Variables
			var closePopup = document.getElementById("popupclose");
			var overlay = document.getElementById("overlay");
			var popup = document.getElementById("popup");
			var button = document.getElementById("button");
			// Close Popup Event
		   
			   // Close Popup Event
			closePopup.onclick = function() {
				overlay.style.display = 'none';
				popup.style.display = 'none';
			};

		</script>	
				
				
							<?php   
								include_once('footer.php');
								?>
						</div><!--maincontentinner-->
				</div><!--maincontent-->
			</div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php 
} //end of else if(flag=n)
?>