  <?php		
include_once('dashboard_tapal.php');
require_once('convert_marathi.php');
################################## Dispatched Letters Details To Allocate Stamps ######################
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tapal Admin System</title>

<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="rightpanel">
        <ul class="breadcrumbs">
            <li><a href="dashboard_tapal.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="dashboard_tapal.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">
				<h4 class="widgettitle">जावक बारनिशी  </h4>      

				<?php 
					$q=mysql_query("SELECT COUNT(*) as TOTAL from stamp_master");
					$r=mysql_fetch_array($q);
					$count=$r['TOTAL']+1;
					
				?>
				<br>
				
				<p>	
					<center><input type="submit" value=" Print Page " onclick="PrintDiv();" class="btn btn-primary"/>
					</center>
				</p>
				
				<table id="dyntable" class="table table-bordered">
                    <thead>
                        <tr>
                            <th class="center" rowspan="2">अ क्र. </th>
                            <th class="center" rowspan="2">जावक दिं. </th>
							<th class="center" rowspan="2">पत्र कोणास पाठविले</th>
							<th class="center" rowspan="2">पत्र क्रमांक</th>
							<th class="center" rowspan="2">डेस्क पत्र क्रमांक</th>
							<th class="center" rowspan="2">केलेली कार्यवाही </th>
							<th class="center" colspan="<?php echo $count; ?>">पोस्टाचे तिकिटे </th>
							<th class="center" rowspan="2">रिमार्क </th>
							<th class="center" rowspan="2">तिकीटाची माहिती लावा </th>
							<th class="center" rowspan="2">टपाल जावक दिं. </th>
						</tr>
						
						<tr>
						<?php 
						$sr_no=1;
						
						$q=mysql_query("SELECT stamp_nm,value from stamp_master");
						while($r=mysql_fetch_array($q))
						{
							echo "<th class='center'>".$r['stamp_nm']."</th>";
						}
					
						?>
						<th class="center">एकूण </th>
						</tr>
						
					</thead>
					<tbody>	
						<?php	
						convert_marathi();
						
						/////////////// dept having desk ////////
						$qry=("SELECT de.desk_ltr_id, de.desk_id_from,di.dispatched_id, de.flag, de.desk_ltr_inword_no,t.desk_ltr_inword_no, de.action_taken, de.desk_ltr_rec_dt,di.desk_inward_no, i.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id,di.tapal_dispatched_date, di.dept_id_from,di.ltr_id, i.subject, 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, di.tic_1, di.tic_2, di.tic_5, di.total, di.remark, i.document, de.scan_doc, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t,incoming_letters_transaction  i, desk_transaction de, dispatched_transaction di 
						WHERE di.dispatched_to='permanent'
						AND de.desk_ltr_inword_no=di.desk_inward_no 
						AND di.desk_ltr_id = de.desk_ltr_id 
						AND i.ltr_id = t.ltr_id 
						AND de.dpt_ltr_id = t.dpt_ltr_id 
						AND i.dpt_inword_no=t.dpt_inword_no 
						AND t.desk_ltr_inword_no=de.desk_ltr_inword_no");
						$rs=mysql_query($qry) or die("".mysql_error());
						
						
						while($rws=mysql_fetch_array($rs))
						{
								/***************************************************************
											fetching dates in dd-mm-yyyy format
								****************************************************************/
								$desdt=strtotime($rws['dispatched_dt']);
								$desdte=date('d-m-Y', $desdt);
								$dptdt=strtotime($rws['dpt_ltr_rec_dt']); 	
								$dptdte=date('d-m-Y', $dptdt);
								$deskdt=strtotime($rws['desk_ltr_rec_dt']); 	
								$dskdte=date('d-m-Y',$deskdt);
								$dept=$rws['dept_id'];
								$id=$rws['dispatched_id'];
								$deskltrid=$rws['desk_ltr_id'];
								$dptltrid=$rws['dpt_ltr_id'];
								$deskid=$rws['desk_id'];
								$desk=mysql_query("Select desk_nm from desk_master where desk_id=' $deskid'");
								$desks=mysql_fetch_array($desk);
								convert_marathi();
								$qry5=("Select * from department_master, incoming_letters_transaction, dispatched_transaction where incoming_letters_transaction.dept_id='$dept' AND department_master.dept_id=incoming_letters_transaction.dept_id AND incoming_letters_transaction.ltr_id=dispatched_transaction.ltr_id");
								$rs5=mysql_query($qry5) or die("dsffsf".mysql_error());
								$row5=mysql_fetch_array($rs5);	  
								?>
								<tr class="gradeX">
								<?php 
									echo "<td class='center'>".$sr_no."</td>
									<td class='center'>".$desdte."</td>
										<td class='center'>".$rws['addressed_to']."</td>
										<td class='center'>".$row5['dept_nm']."/<br>".$rws['outword_no']."/<br>".$dptdte."</td>
										<td class='center'>".$desks['desk_nm']."/<br>".$rws['desk_ltr_inword_no']."/<br>". $dskdte."</td>
										<td class='center'>".$rws['action_taken']."</td>";
									
								/*		echo "<td class='center'>".$rws['tic_1']."</td>
										<td class='center'>".$rws['tic_2']."</td>
										<td class='center'>".$rws['tic_5']."</td>";     */
										
										$str=$rws['tic_1'];
										if($str==0)
										{
											$q=mysql_query("SELECT stamp_id,stamp_nm,value from stamp_master");
											while($r=mysql_fetch_array($q))
											{
												echo "<td class='center'>0</td>";
											}
										}
										else
										{
											$ab=explode(",",$str);
											for($i=0;$i<count($ab); $i++)
											{
												$a= explode(":",$ab[$i]);
												echo "<td class='center'>".$a[1]."</td>";
												if($a[1]!='0')
												{
													$q=mysql_query("SELECT stamp_id from stamp_master where value='$a[0]' ");
													$r=mysql_fetch_array($q);
													$stmpid=$r['stamp_id'];
													$amount=$a[0]*$a[1];
													$curdate=date("Y-m-d");
													$sendernm=$rws['addressed_to'];
													$qry=mysql_query("INSERT into stamp_purchase_details
													(stamp_id,quantity,amount,purchase_dt,sender_nm,p_s_flag) values ('$stmpid','$a[1]','$amount','$curdate','$sendernm','s')") OR die("dssd".mysql_error());
												}
											}
										}
										echo "<td class='center'>".$rws['total']."</td>
										<td class='center'>".$rws['remark']."</td>
										<td class='center'><a href=allocate_stamp_form.php?id=$id>Edit</a><br><a href=view_document.php?deskltrid=$deskltrid&no=2><font color=red>Print Documents</font></a></td>
										<td class='center'>".$rws['tapal_dispatched_date']."</td>
								</tr>";
								$sr_no++;
							} 

							//////////////dept not having desk ///////////
							$qry1=("SELECT di.dispatched_id,t.action_taken,t.dispatched_date, t.desk_ltr_inword_no, di.desk_inward_no, i.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id,di.tapal_dispatched_date, di.dept_id_from,di.ltr_id, i.subject, di.addressed_to,  i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, di.tic_1, di.tic_2, di.tic_5, di.total, di.remark, i.document, di.outword_no, di.dispatched_to,t.dpt_ltr_id
							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 di.dispatched_to='permanent' AND t.ltr_status='dispatched' ");
							$rs1=mysql_query($qry1) or die("".mysql_error());
						
							while($rws=mysql_fetch_array($rs1))
							{
								/***************************************************************
											fetching dates in dd-mm-yyyy format
								****************************************************************/
								$desdt=strtotime($rws['dispatched_date']);
								$desdte=date('d-m-Y', $desdt);
								$dptdt=strtotime($rws['dpt_ltr_rec_dt']); 	
								$dptdte=date('d-m-Y', $dptdt);
								$deskdt=strtotime($rws['desk_ltr_rec_dt']); 	
								$dskdte=date('d-m-Y',$deskdt);
								$dept=$rws['dept_id'];
								$id=$rws['dispatched_id'];
								$deskltrid=$rws['desk_ltr_id'];
								$dptltrid=$rws['dpt_ltr_id'];
								$deskid=$rws['desk_id'];
								$desk=mysql_query("Select desk_nm from desk_master where desk_id=' $deskid'");
								$desks=mysql_fetch_array($desk);
								convert_marathi();
								$qry5=("Select * from department_master, incoming_letters_transaction, dispatched_transaction where incoming_letters_transaction.dept_id='$dept' AND department_master.dept_id=incoming_letters_transaction.dept_id AND incoming_letters_transaction.ltr_id=dispatched_transaction.ltr_id");
								$rs5=mysql_query($qry5) or die("dsffsf".mysql_error());
								$row5=mysql_fetch_array($rs5);	  
								?>
								<tr class="gradeX">
								<?php 
									echo "<td class='center'>".$sr_no."</td>
									<td class='center'>".$desdte."</td>
										<td class='center'>".$rws['addressed_to']."</td>
										<td class='center'>".$row5['dept_nm']."/<br>".$rws['outword_no']."/<br>".$dptdte."</td>
										<td class='center'> -- </td>
										<td class='center'>".$rws['action_taken']."</td>";
										
								/*		echo "<td class='center'>".$rws['tic_1']."</td>
										<td class='center'>".$rws['tic_2']."</td>
										<td class='center'>".$rws['tic_5']."</td>";   */
										
										$str=$rws['tic_1'];
										if($str==0)
										{
											$q=mysql_query("SELECT stamp_id,stamp_nm,value from stamp_master");
											while($r=mysql_fetch_array($q))
											{
												echo "<td class='center'>0</td>";
											}
										}
										else
										{
											$ab=explode(",",$str);
											for($i=0;$i<count($ab); $i++)
											{
												$a= explode(":",$ab[$i]);
												echo "<td class='center'>".$a[1]."</td>";
												if($a[1]!='0')
												{
													$q=mysql_query("SELECT stamp_id from stamp_master where value='$a[0]' ");
													$r=mysql_fetch_array($q);
													$stmpid=$r['stamp_id'];
													$amount=$a[0]*$a[1];
													$curdate=date("Y-m-d");
													$sendernm=$rws['addressed_to'];
													$qry=mysql_query("INSERT into stamp_purchase_details
													(stamp_id,quantity,amount,purchase_dt,sender_nm,p_s_flag) values ('$stmpid','$a[1]','$amount','$curdate','$sendernm','s')") OR die("dssd".mysql_error());
												}
											}
										}
										
										echo "<td class='center'>".$rws['total']."</td>
										<td class='center'>".$rws['remark']."</td>
										<td class='center'><a href=allocate_stamp_form.php?id=$id>Edit</a><br><a href=view_document.php?flag=n&dptltrid=$dptltrid&deskltrid=$deskltrid&no=2><font color=red>Print Documents</font></a></td>
										<td class='center'>".$rws['tapal_dispatched_date']."</td>
								</tr>";
								
								$sr_no++;
							}
							
							
							?>
                    </tbody>
                </table>
				
              <br/>
			  
			 
			  
			  
			  
			  <?php
			  
			  echo "<div id='divToPrint' style='display:none;'>";
						echo ' <div style="margin-left:25%;"><div style="float:left;margin-top:3%"> <img src="images\t-soba.png" style="height:105px;width:115px;" alt=""> </div> <div style="float:left;">  <h2>पोलीस अधिक्षक कार्यालय, <br> जि.रायगड <br> जावक बारनिशी &nbsp;&nbsp; Outward Register <h2> </div></div>';	
						
						
						$sr_no=1;
						?>
							
					<table id="dyntable" border="1px" class="table table-bordered" style="border-collapse:collapse;width:1000px;text-align :center;">
                    <thead>
                        <tr>
                            	<th class="center" rowspan="2">अ क्र.  </th>
                            	<th class="center" rowspan="2">जावक दिं. </th>
							<th class="center" rowspan="2">पत्र कोणास पाठविले</th>
							<th class="center" rowspan="2">पत्र क्रमांक</th>
							<th class="center" rowspan="2">डेस्क पत्र क्रमांक</th>
							<th class="center" rowspan="2">केलेली कार्यवाही </th>
							<th class="center" colspan="<?php echo $count; ?>">पोस्टाचे तिकिटे </th>
							<th class="center" rowspan="2">रिमार्क </th>
							<th class="center" rowspan="2">टपाल जावक दिं. </th>
						</tr>
						
						<tr>
						<?php 
						$q=mysql_query("SELECT stamp_nm,value from stamp_master");
						while($r=mysql_fetch_array($q))
						{
							echo "<th class='center'>".$r['stamp_nm']."</th>";
						}
					
						?>
						<th class="center">एकूण </th>
						</tr>
						
					</thead>
					<tbody>	
						<?php	
						convert_marathi();
						
						/////////////// dept having desk ////////
						$qry=("SELECT de.desk_ltr_id, de.desk_id_from,di.dispatched_id, de.flag, de.desk_ltr_inword_no,t.desk_ltr_inword_no, de.action_taken, de.desk_ltr_rec_dt,di.desk_inward_no, i.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id,di.tapal_dispatched_date, di.dept_id_from,di.ltr_id, i.subject, 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, di.tic_1, di.tic_2, di.tic_5, di.total, di.remark, i.document, de.scan_doc, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no FROM tapal_to_dpt_transaction t,incoming_letters_transaction  i, desk_transaction de, dispatched_transaction di 
						WHERE di.dispatched_to='permanent'
						AND de.desk_ltr_inword_no=di.desk_inward_no 
						AND di.desk_ltr_id = de.desk_ltr_id 
						AND i.ltr_id = t.ltr_id 
						AND de.dpt_ltr_id = t.dpt_ltr_id 
						AND i.dpt_inword_no=t.dpt_inword_no 
						AND t.desk_ltr_inword_no=de.desk_ltr_inword_no");
						$rs=mysql_query($qry) or die("".mysql_error());
						
						//////////////dept not having desk ///////////
						$qry1=("SELECT di.dispatched_id,t.action_taken,t.dispatched_date, t.desk_ltr_inword_no, di.desk_inward_no, i.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id,di.tapal_dispatched_date, di.dept_id_from,di.ltr_id, i.subject, di.addressed_to,  i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, di.tic_1, di.tic_2, di.tic_5, di.total, di.remark, i.document, di.outword_no, di.dispatched_to,t.dpt_ltr_id
						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 di.dispatched_to='permanent' AND t.ltr_status='dispatched' ");
						$rs1=mysql_query($qry1) or die("".mysql_error());
						while($rws=mysql_fetch_array($rs))
						{
								/***************************************************************
											fetching dates in dd-mm-yyyy format
								****************************************************************/
								$desdt=strtotime($rws['dispatched_dt']);
								$desdte=date('d-m-Y', $desdt);
								$dptdt=strtotime($rws['dpt_ltr_rec_dt']); 	
								$dptdte=date('d-m-Y', $dptdt);
								$deskdt=strtotime($rws['desk_ltr_rec_dt']); 	
								$dskdte=date('d-m-Y',$deskdt);
								$dept=$rws['dept_id'];
								$id=$rws['dispatched_id'];
								$deskltrid=$rws['desk_ltr_id'];
								$dptltrid=$rws['dpt_ltr_id'];
								$deskid=$rws['desk_id'];
								$desk=mysql_query("Select desk_nm from desk_master where desk_id=' $deskid'");
								$desks=mysql_fetch_array($desk);
								convert_marathi();
								$qry5=("Select * from department_master, incoming_letters_transaction, dispatched_transaction where incoming_letters_transaction.dept_id='$dept' AND department_master.dept_id=incoming_letters_transaction.dept_id AND incoming_letters_transaction.ltr_id=dispatched_transaction.ltr_id");
								$rs5=mysql_query($qry5) or die("dsffsf".mysql_error());
								$row5=mysql_fetch_array($rs5);	  
								?>
								<tr class="gradeX">
								<?php 
									echo "<td class='center'>".$sr_no."</td>
									<td class='center'>".$desdte."</td>
										<td class='center'>".$rws['addressed_to']."</td>
										<td class='center'>".$row5['dept_nm']."/<br>".$rws['outword_no']."/<br>".$dptdte."</td>
										<td class='center'>".$desks['desk_nm']."/<br>".$rws['desk_ltr_inword_no']."/<br>". $dskdte."</td>
										<td class='center'>".$rws['action_taken']."</td>";
									
								/*		echo "<td class='center'>".$rws['tic_1']."</td>
										<td class='center'>".$rws['tic_2']."</td>
										<td class='center'>".$rws['tic_5']."</td>";     */
										
										$str=$rws['tic_1'];
										if($str==0)
										{
											$q=mysql_query("SELECT stamp_id,stamp_nm,value from stamp_master");
											while($r=mysql_fetch_array($q))
											{
												echo "<td class='center'>0</td>";
											}
										}
										else
										{
											$ab=explode(",",$str);
											for($i=0;$i<count($ab); $i++)
											{
												$a= explode(":",$ab[$i]);
												echo "<td class='center'>".$a[1]."</td>";
												if($a[1]!='0')
												{
													$q=mysql_query("SELECT stamp_id from stamp_master where value='$a[0]' ");
													$r=mysql_fetch_array($q);
													$stmpid=$r['stamp_id'];
													$amount=$a[0]*$a[1];
													$curdate=date("Y-m-d");
													$sendernm=$rws['addressed_to'];
													$qry=mysql_query("INSERT into stamp_purchase_details
													(stamp_id,quantity,amount,purchase_dt,sender_nm,p_s_flag) values ('$stmpid','$a[1]','$amount','$curdate','$sendernm','s')") OR die("dssd".mysql_error());
												}
											}
										}
										echo "<td class='center'>".$rws['total']."</td>
										<td class='center'>".$rws['remark']."</td>
										<td class='center'>".$rws['tapal_dispatched_date']."</td>
								</tr>";
								$sr_no++;
							} 

							while($rws=mysql_fetch_array($rs1))
							{
								/***************************************************************
											fetching dates in dd-mm-yyyy format
								****************************************************************/
								$desdt=strtotime($rws['dispatched_date']);
								$desdte=date('d-m-Y', $desdt);
								$dptdt=strtotime($rws['dpt_ltr_rec_dt']); 	
								$dptdte=date('d-m-Y', $dptdt);
								$deskdt=strtotime($rws['desk_ltr_rec_dt']); 	
								$dskdte=date('d-m-Y',$deskdt);
								$dept=$rws['dept_id'];
								$id=$rws['dispatched_id'];
								$deskltrid=$rws['desk_ltr_id'];
								$dptltrid=$rws['dpt_ltr_id'];
								$deskid=$rws['desk_id'];
								$desk=mysql_query("Select desk_nm from desk_master where desk_id=' $deskid'");
								$desks=mysql_fetch_array($desk);
								convert_marathi();
								$qry5=("Select * from department_master, incoming_letters_transaction, dispatched_transaction where incoming_letters_transaction.dept_id='$dept' AND department_master.dept_id=incoming_letters_transaction.dept_id AND incoming_letters_transaction.ltr_id=dispatched_transaction.ltr_id");
								$rs5=mysql_query($qry5) or die("dsffsf".mysql_error());
								$row5=mysql_fetch_array($rs5);	  
								?>
								<tr class="gradeX">
								<?php 
									echo "<td class='center'>".$sr_no."</td>
									<td class='center'>".$desdte."</td>
										<td class='center'>".$rws['addressed_to']."</td>
										<td class='center'>".$row5['dept_nm']."/<br>".$rws['outword_no']."/<br>".$dptdte."</td>
										<td class='center'> -- </td>
										<td class='center'>".$rws['action_taken']."</td>";
										
								/*		echo "<td class='center'>".$rws['tic_1']."</td>
										<td class='center'>".$rws['tic_2']."</td>
										<td class='center'>".$rws['tic_5']."</td>";   */
										
										$str=$rws['tic_1'];
										if($str==0)
										{
											$q=mysql_query("SELECT stamp_id,stamp_nm,value from stamp_master");
											while($r=mysql_fetch_array($q))
											{
												echo "<td class='center'>0</td>";
											}
										}
										else
										{
											$ab=explode(",",$str);
											for($i=0;$i<count($ab); $i++)
											{
												$a= explode(":",$ab[$i]);
												echo "<td class='center'>".$a[1]."</td>";
												if($a[1]!='0')
												{
													$q=mysql_query("SELECT stamp_id from stamp_master where value='$a[0]' ");
													$r=mysql_fetch_array($q);
													$stmpid=$r['stamp_id'];
													$amount=$a[0]*$a[1];
													$curdate=date("Y-m-d");
													$sendernm=$rws['addressed_to'];
													$qry=mysql_query("INSERT into stamp_purchase_details
													(stamp_id,quantity,amount,purchase_dt,sender_nm,p_s_flag) values ('$stmpid','$a[1]','$amount','$curdate','$sendernm','s')") OR die("dssd".mysql_error());
												}
											}
										}
										
										echo "<td class='center'>".$rws['total']."</td>
										<td class='center'>".$rws['remark']."</td>
										<td class='center'>".$rws['tapal_dispatched_date']."</td>
								</tr>";
								$sr_no++;
							}
							
							
							echo "</div>";
				
					?>
			  
			  
			  
			  
			  
			  
			  
			  
			    <?php //include_once('footer.php');?>
			  
               
            </div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>