<!DOCTYPE html>
<?php
$flag=$_REQUEST['flag'];
if($flag=='')
{
####################################### Display Reference Wise Report TO Department #####################################
include('dashboard_department.php');
require_once('convert_marathi.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 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);
				?>
                <h1><?php echo 	$rsz['dept_nm'];?> चे संदर्भानुसार रिपोर्ट्स</h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
			    <h4 class="widgettitle"> <?php echo $rsz['dept_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="4">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDate()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
						<table id="dyntable" class="table table-bordered">
							<thead>
							<tr>
								<th class="head0 center">डेस्कचा आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class="head1 center">विभागीय आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class="head0 center">आवक_क्रमांक<br>आवक_दिनांक</th>
								<th class="head1 center">संदर्भ_क्रमांक<br>प्राप्त_दिनांक</th>                          
								<th class="head0 center">कोणाकडून प्राप्त झाला </th>
								<th class="head0 center">विषय</th>                         
								<th class="head1 center"> केलेली कार्यवाही </th>
								<th class="head1 center">View_status</th>
							</tr>
							</thead>
							<?php
							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>';
								$id1 = $date1;
								$id2= $date2;
								$result222=mysql_query("SELECT d.ltr_status,d.desk_ltr_rec_dt, t.dpt_ltr_rec_dt, i.ref_dt, i.receive_dt, d.desk_ltr_inword_no, t.dpt_inword_no, i.ltr_inword_no, i.ref_no, i.sender_name, i.subject, d.action_taken, d.ltr_category
								FROM desk_transaction d, incoming_letters_transaction i, tapal_to_dpt_transaction t where t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND d.dpt_ltr_id=t.dpt_ltr_id 
								AND t.ltr_id=i.ltr_id");
							}
							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 d.ltr_status,d.desk_ltr_rec_dt, t.dpt_ltr_rec_dt, i.ref_dt, i.receive_dt, d.desk_ltr_inword_no, t.dpt_inword_no, i.ltr_inword_no, i.ref_no, i.sender_name, i.subject, d.action_taken, d.ltr_category
								FROM desk_transaction d, incoming_letters_transaction i, tapal_to_dpt_transaction t where t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND d.dpt_ltr_id=t.dpt_ltr_id 
								AND t.ltr_id=i.ltr_id AND (i.receive_dt BETWEEN '$date1' AND '$date2')");
							}
							$count=mysql_num_rows($result222);
							//echo "total id".$count;
							while($rws = mysql_fetch_array($result222))
							{
								$dsrecdt = strtotime($rws['desk_ltr_rec_dt']);
								$dsrecdt1= date('d-m-Y', $dsrecdt);
								$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
								$dprecdt1= date('d-m-Y', $dprecdt);
								$refdt = strtotime($rws['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rws['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);
								?>
								<tr class="gradeX">
								<?php 
								echo "<td class='center'>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1." </td>
										<td class='center'>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
										echo "<td class='center'>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
										<td class='center'>".$rws['ref_no']."<br>".$refdt1."</td>
										<td class='center'>".$rws['sender_name']."</td><td class='center'>".$rws['subject']."</td>";
										if($rws['action_taken']=='')
										{
											echo "<td class='center'><font color='red'>". "कार्यवाही करणे बाकी "."</font></td>";
										}
										else if($rws['ltr_status']=='')
										{
											echo "<td class='center'><font color='red'>". "कार्यवाही करणे बाकी "."</font></td>";
										}
										else
										{
											echo "<td class='center'>".$rws['action_taken']."</td>";
										}
										
										if($rws['ltr_category']=='')
										{
											echo "<td class='center'><font color='red'>". "संदर्भ लावणे बाकी "."</font></td>";
										}
										else if($rws['ltr_category']=='current')
										{		
											echo "<td class='center'>".$rws['ltr_category']."<br><a href=report_dpt_refwise_op.php?refno=$rws[assign_no]>".$rws['assign_no']."</a></td>";
										}
										else
										{
											echo "<td class='center'>".$rws['ltr_category']."</td>";
										}
                                echo" </select></tr>";
							}
						//mysql_close();
						echo	"</tbody></table>";
						
						echo "<div id='divToPrint' style='display:none;'>
							<table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='9'><center><h4>".$rsz['dept_nm'] ." चे संदर्भानुसार रिपोर्ट्स  </h4></center></td></tr>
							<tr>
								<th>डेस्कचा आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>विभागीय आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ_क्रमांक<br>प्राप्त_दिनांक</th>                          
								<th>कोणाकडून प्राप्त झाला </th>
								<th>विषय</th>                         
								<th> केलेली कार्यवाही </th>
								<th>View_status</th>
							</tr>";
							convert_marathi();
							if($date123==''&& $date223=='')
							{
								$result222=mysql_query("SELECT d.ltr_status,d.desk_ltr_rec_dt, t.dpt_ltr_rec_dt, i.ref_dt, i.receive_dt, d.desk_ltr_inword_no, t.dpt_inword_no, i.ltr_inword_no, i.ref_no, i.sender_name, i.subject, d.action_taken, d.ltr_category
								FROM desk_transaction d, incoming_letters_transaction i, tapal_to_dpt_transaction t where t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND d.dpt_ltr_id=t.dpt_ltr_id 
								AND t.ltr_id=i.ltr_id");
							}
							else
							{
								$result222=mysql_query("SELECT d.ltr_status,d.desk_ltr_rec_dt, t.dpt_ltr_rec_dt, i.ref_dt, i.receive_dt, d.desk_ltr_inword_no, t.dpt_inword_no, i.ltr_inword_no, i.ref_no, i.sender_name, i.subject, d.action_taken, d.ltr_category
								FROM desk_transaction d, incoming_letters_transaction i, tapal_to_dpt_transaction t where t.dept_id_from=(select dept_id from login where login_id='$username') 
								AND d.dpt_ltr_id=t.dpt_ltr_id 
								AND t.ltr_id=i.ltr_id AND (i.receive_dt BETWEEN '$date1' AND '$date2')");
							}
							$count=mysql_num_rows($result222);
							//echo "total id".$count;
							while($rws = mysql_fetch_array($result222))
							{
								$dsrecdt = strtotime($rws['desk_ltr_rec_dt']);
								$dsrecdt1= date('d-m-Y', $dsrecdt);
								$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
								$dprecdt1= date('d-m-Y', $dprecdt);
								$refdt = strtotime($rws['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rws['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);
								echo "<tr>";
								echo "<td style='text-align:center;'>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1." </td>
										<td style='text-align:center;'>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
										echo "<td style='text-align:center;'>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
										<td style='text-align:center;'>".$rws['ref_no']."<br>".$refdt1."</td>
										<td style='text-align:center;'>".$rws['sender_name']."</td><td>".$rws['subject']."</td>";
										if($rws['action_taken']=='')
										{
											echo "<td style='text-align:center;'>". "कार्यवाही करणे बाकी "."</td>";
										}
										else if($rws['ltr_status']=='')
										{
											echo "<td class='center'>". "कार्यवाही करणे बाकी "."</td>";
										}
										else
										{
											echo "<td style='text-align:center;'>".$rws['action_taken']."</td>";
										}
										
										
										if($rws['ltr_category']=='')
										{
											echo "<td class='center'>". "संदर्भ लावणे बाकी "."</td>";
										}
										else if($rws['ltr_category']=='current')
										{		
											echo "<td style='text-align:center;'>".$rws['ltr_category']."<br>".$rws['assign_no']."</td>";
										}
										else
										{
											echo "<td style='text-align:center;'>".$rws['ltr_category']."</td>";
										}
                                echo "</tr>";
							}
						//mysql_close();
						echo	"</table></div>";
						?>
						<br>
						<p>	
							<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
							<input type="button" class="btn" onclick="tableToExcel('dyntable', 'W3C Example Table')" value="Export to Excel"></center>
						</p>
				</form>
                <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel--> 
</div><!--mainwrapper-->
</body>
</html>
<?php 
} //if($flag=='')

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

else if($flag=='n')
{
####################################### Display Reference Wise Report TO Department #####################################
include('new_dashboard_department.php');
require_once('convert_marathi.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 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);
				?>
                <h1><?php echo 	$rsz['dept_nm'];?> चे संदर्भानुसार रिपोर्ट्स</h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
			    <h4 class="widgettitle"> <?php echo $rsz['dept_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="4">
								<div align="center">
									<input type="submit" onClick="return sadyasthitiDate()" name="ok" value="GO"/>
									<input type="reset" value="CLEAR" name="clear"/>
								</div>
								</td>
							</tr>
						</table>
					</div>
						<table id="dyntable" class="table table-bordered">
							<thead>
							<!--	<tr>
									<th class="head0 center">डेस्कचा आवक_क्रमांक<br>आवक_दिनांक</th>
									<th class="head1 center">विभागीय आवक_क्रमांक<br>आवक_दिनांक</th>
									<th class="head0 center">आवक_क्रमांक<br>आवक_दिनांक</th>
									<th class="head1 center">संदर्भ_क्रमांक<br>प्राप्त_दिनांक</th>                          
									<th class="head0 center">कोणाकडून प्राप्त झाला </th>
									<th class="head0 center">विषय</th>                         
									<th class="head1 center"> केलेली कार्यवाही </th>
									<th class="head1 center">View_status</th>
								</tr> -->
								<tr>
									<th class="head1 center">विभागीय आवक_क्रमांक<br>आवक_दिनांक</th>
									<th class="head0 center">आवक_क्रमांक<br>आवक_दिनांक</th>
									<th class="head1 center">संदर्भ_क्रमांक<br>प्राप्त_दिनांक</th>                          
									<th class="head0 center">कोणाकडून प्राप्त झाला </th>
									<th class="head0 center">विषय</th>                         
									<th class="head1 center"> केलेली कार्यवाही </th>
									<th class="head1 center">View_status</th>
								</tr>
							</thead>
							<?php
							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>';
								$id1 = $date1;
								$id2= $date2;
								/*$result222=mysql_query("SELECT * FROM desk_transaction, incoming_letters_transaction, tapal_to_dpt_transaction where tapal_to_dpt_transaction.dept_id_from=(select dept_id from login where login_id='$username') AND desk_transaction.dpt_ltr_id=tapal_to_dpt_transaction.dpt_ltr_id AND tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id");*/
								
								$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.ltr_id=i.ltr_id");
							}
							else
							{
								echo '<br><br><center><h4>दिनांक <font color="#59c600">'.$date123.'</font>'.' पासून दिनांक '.'<font color="#59c600">'.$date223.'</font></center></h4><br>';
								$id1 = $date1;
								$id2= $date2;
								$result222=mysql_query("SELECT * FROM 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.ltr_id=i.ltr_id AND (incoming_letters_transaction.receive_dt BETWEEN '$date1' AND '$date2')");
							}
							$count=mysql_num_rows($result222);
							//echo "total id".$count;
							while($rws = mysql_fetch_array($result222))
							{
							/*	$dsrecdt = strtotime($rws['desk_ltr_rec_dt']);
								$dsrecdt1= date('d-m-Y', $dsrecdt);  */
								$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
								$dprecdt1= date('d-m-Y', $dprecdt);
								$refdt = strtotime($rws['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rws['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);
								?>
								<tr class="gradeX">
								<?php 
								//echo "<td class='center'>".$rws['desk_ltr_inword_no']."<br>".$dsrecdt1." </td>";
								echo "<td class='center'>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
										echo "<td class='center'>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
										<td class='center'>".$rws['ref_no']."<br>".$refdt1."</td>
										<td class='center'>".$rws['sender_name']."</td><td class='center'>".$rws['subject']."</td>";
										if($rws['ltr_status']=='')
										{
											echo "<td class='center'><font color='red'>". "कार्यवाही करणे बाकी "."</font></td>";
										}
										else
										{
											echo "<td class='center'>".$rws['action_taken']."</td>";
										}
										
										if($rws['ltr_category']=='current')
										{		
											echo "<td class='center'>".$rws['ltr_category']."<br><a href=report_dpt_refwise_op.php?flag=n&refno=$rws[assign_no]>".$rws['assign_no']."</a></td>";
										}
										else if($rws['ltr_category']=='' || $rws['ltr_category']=='NULL')
										{
											echo "<td class='center'><font color='red'>". "संदर्भ लावणे बाकी "."</font></td>";
										}
										else
										{
											echo "<td class='center'>".$rws['ltr_category']."</td>";
										}
                                echo" </select></tr>";
							}
						//mysql_close();
						echo	"</tbody></table>";
						
						echo "<div id='divToPrint' style='display:none;'>
							<table id='export' border='1px' style='margin-left:50px;'>
							<tr><td colspan='9'><center><h4>".$rsz['dept_nm'] ." चे संदर्भानुसार रिपोर्ट्स  </h4></center></td></tr>
							<tr>
								<th>विभागीय आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>आवक_क्रमांक<br>आवक_दिनांक</th>
								<th>संदर्भ_क्रमांक<br>प्राप्त_दिनांक</th>                          
								<th>कोणाकडून प्राप्त झाला </th>
								<th>विषय</th>                         
								<th> केलेली कार्यवाही </th>
								<th>View_status</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.ltr_id=i.ltr_id");
							$count=mysql_num_rows($result222);
							//echo "total id".$count;
							while($rws = mysql_fetch_array($result222))
							{
								//$dsrecdt = strtotime($rws['desk_ltr_rec_dt']);
								//$dsrecdt1= date('d-m-Y', $dsrecdt);
								$dprecdt = strtotime($rws['dpt_ltr_rec_dt']);
								$dprecdt1= date('d-m-Y', $dprecdt);
								$refdt = strtotime($rws['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rws['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);
								echo "<tr>";
								echo "
										<td style='text-align:center;'>".$rws['dpt_inword_no']."<br>".$dprecdt1." </td>";
										echo "<td style='text-align:center;'>".$rws['ltr_inword_no']."<br>".$recdt1." </td>
										<td style='text-align:center;'>".$rws['ref_no']."<br>".$refdt1."</td>
										<td style='text-align:center;'>".$rws['sender_name']."</td><td>".$rws['subject']."</td>";
										if($rws['ltr_status']=='')
										{
											echo "<td style='text-align:center;'>". "कार्यवाही करणे बाकी "."</td>";
										}
										else
										{
											echo "<td style='text-align:center;'>".$rws['action_taken']."</td>";
										}
										
										if($rws['ltr_category']=='current')
										{		
											echo "<td style='text-align:center;'>".$rws['ltr_category']."<br>".$rws['assign_no']."</td>";
										}
										else if($rws['ltr_category']=='' || $rws['ltr_category']=='NULL')
										{
											echo "<td class='center'>". "संदर्भ लावणे बाकी "."</td>";
										}
										else
										{
											echo "<td style='text-align:center;'>".$rws['ltr_category']."</td>";
										}
                                echo "</tr>";
							}
						//mysql_close();
						echo	"</table></div>";
						?>
						<br>
						<p>	
							<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
							<input type="button" class="btn" onclick="tableToExcel('dyntable', 'W3C Example Table')" value="Export to Excel"></center>
						</p>
				</form>
                <?php include_once('footer.php'); ?>
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel--> 
</div><!--mainwrapper-->
</body>
</html>
<?php 
} //else if($flag=='n')
?>