<?php error_reporting(0);  
	$PageSecurity = 3;
	include ('includes/session.inc');
	include ('includes/function_lib.php');
	include('includes/fun-php.php');
	include('includes/fun-HRClass.php');
 	global $db; 
?>
<title>Stock Ledger Report</title>
<link rel="stylesheet" href="css/purchase_requision_print.css">
<div class="body_contain">
<div class="tab_div">
<?php  
$logo="<div>";
$logo.="<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
$logo.="<tr>";
$logo.="<td align='left'><img src='images/cloud_logo.jpg' /></td>";
$logo.="<td align='right'><img src='images/right_img.jpg' /></td>";
$logo.="</tr>";
$logo.="<tr>";
$logo.="<td colspan='2'><h1>".'Stock Ledger Report'."</h1></td>";
$logo.="</tr>";
$logo.="</table>";
$logo.="</div>";
echo $logo;
$Header1="<p align='center' style='font-size:12px;font-weight:bold;'>".$_SESSION['mess1']."</p>";
echo $Header1;
?>
<!--<div id="foo">
  <p align="center"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div> --> 
<?php 

/*<table width="90%" border="0" cellspacing="1" cellpadding="2" align="center" style="border:1px solid #000;background-color:#FFF">
    <tr>
      <th width="21%"  class="jjrs_tablehead">Item Desc</th>
      <td width="28%"  class="jjrs_tablehead"><?php echo $s->getField('item_master','id',$_REQUEST['item'],'item_name');?></td>
	   <th width="22%"  class="jjrs_tablehead">Unit</th>
      <td width="29%"  class="jjrs_tablehead"><?php echo $s->getField('unitsofmeasure','unitid',$s->getField('item_master','id',$_REQUEST['item'],'unit'),'unitname');?></td>
    </tr>*/
	
	   $filt=''; 
	 
	   		if($_REQUEST['site']!='0')
			$filt[]="site = '".$_REQUEST['site']."'";
			if($_REQUEST['store1']!='0')
	   		$filt[]="store = '".$_REQUEST['store1']."'";
			if($_REQUEST['item']!='0')
	   		$filt[]="mstid = '".$_REQUEST['item']."'";
			if($_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
			$filt[]="reveive_date <= '".str_replace('/','-',FormatDateForSQL($_REQUEST['to_date']))."'";
			
			if($filt!='')
	   		{
				$filt=implode(' and ',$filt);
			}
			
			//echo "Select stock,reveive_date from opening_stockitemwise where $filt";
			$op_sql=DB_fetch_array(DB_query("Select stock,reveive_date from opening_stockitemwise where $filt",$db));
			$stock=((float)$op_sql['stock']);
			
	  
	   
	   ?>
   
 </table>
<p>
<?php   
$fordate = $_REQUEST['from_date'];
$todate = $_REQUEST['to_date'];
$fromdate = explode("/", $fordate);
$daydate = $fromdate['0'];
$Monthdate = $fromdate['1'];
$yeardate = $fromdate['2'];
 $fdate = $yeardate."-".$Monthdate."-".$daydate;
					   
$tredate   = explode("/", $todate);
$dayda     = $tredate['0'];
$Monthda   = $tredate['1'];
$yearda    = $tredate['2'];
$toyrdate  = $yearda."-".$Monthda."-".$dayda;
?>

<?php 

	$filter = array();
	if($_REQUEST['site']!='0')
	{
  	$filter[]=$_REQUEST['site'];
	}
	if($_REQUEST['store1']!='')
	{
	$filter[]=$_REQUEST['store1'];
	}
	if($_POST['from_date']!='')
	{
 	$filter[]=$fdate;
    }
	if($_POST['to_date']!='')
	{ 
	$filter[]=$toyrdate;
	}
	
	
	$filter2=implode(",",$filter);
	
	
	$data=array();
	
	
	/*******************************************  Opening ******************************************************/
	$sqlopen=DB_query("select reveive_date as date,mstid as itemid,stock as reciveqty
	from opening_stockitemwise  where site='".$_REQUEST['site']."'
	 and store='".$_REQUEST['store1']."' and reveive_date between '".$fdate."' 
	 and '".$toyrdate."' and mstid='".$_REQUEST['item']."'",$db);
	  $num1=DB_num_rows($sqlopen);
	 if($num1>0)
	 {
	while($addopen=DB_fetch_array($sqlopen))
	{	
	//$vender=$s->getField('suppliers','id',$addmrn['vendor'],'vendor_name');
	$data[]=array('slipno'=>$addopen['slipno'],'itemid'=>$addopen['itemid'],
	'date'=>$addopen['date'],'reciveqty'=>$addopen['reciveqty'],'issueqty'=>'','doc'=>'','description'=>'Opening');
	}
	}
	else
	{
	$receive=array();
	$issueqty=array();	
	/**************************************  MRN *********************************************/
	
	$sqlmrn=DB_query("select sum(reciveqty) as reciveqty from addmrnqty 
	inner join addmrn on addmrn.id=addmrnqty.issue_id  where site='".$_REQUEST['site']."'
	 and StoreCode='".$_REQUEST['store1']."' and MRNDate <='".$fdate."' 
	 and MRNDate <='".$toyrdate."' and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addmrn=DB_fetch_array($sqlmrn))
	{	
	$receive[]=$addmrn['reciveqty'];
	}	
	
	
	       
		   
	       /**************************************  Issue *********************************************/
	$sqlissue=DB_query("SELECT sum(issueqty) AS issueqty FROM 
                        issueqty INNER JOIN addissue ON addissue.id=issueqty.issue_id where site='".$_REQUEST['site']."' and
						mst_storeid='".$_REQUEST['store1']."' 
						and issuedate <='".$fdate."' and issuedate <='".$toyrdate."' and mst_itemid='".$_REQUEST['item']."' ",$db);	
	while($addissue=DB_fetch_array($sqlissue))
	{
	$issueqty[]=$addissue['issueqty'];
	}
			
	/**************************************  Receive *********************************************/
	$sqlreceive=DB_query("SELECT sum(receiveqty) AS reciveqty
	                    FROM  material_return_details INNER JOIN material_return 
				        ON material_return.id=material_return_details.parentId where site='".$_REQUEST['site']."' and
						store='".$_REQUEST['store1']."' and returndate <='".$fdate."' and returndate <='".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addreceive=DB_fetch_array($sqlreceive))
	{
	$receive[]=$addreceive['reciveqty'];
	}
	
	
	/**************************************  site to site *********************************************/
	$sqlsite_site=DB_query("SELECT sum(issueqty) AS issueqty
	                     FROM  transfer_issue_details INNER JOIN transfer_issue 
				        ON transfer_issue.id=transfer_issue_details.transfer_issue_id where sitecode='".$_REQUEST['site']."' and
						fromstore='".$_REQUEST['store1']."' and issuedate <= '".$fdate."'  and  issuedate <='".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addsitetosite=DB_fetch_array($sqlsite_site))
	{
	$issueqty[]=$addsitetosite['issueqty'];
	}
	
	
	/**************************************  site to site receive *********************************************/
	$sqlsite_site1=DB_query("SELECT sum(reciveqty) AS reciveqty
	                      FROM  transfer_receipt_details INNER JOIN transfer_receipt 
				        ON transfer_receipt.id=transfer_receipt_details.transfer_receipt_id
						 where sitecode='".$_REQUEST['site']."' and
						store='".$_REQUEST['store1']."' and MRNDate <= '".$fdate."' and MRNDate <='".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addsitetositereceive=DB_fetch_array($sqlsite_site1))
	{
	$receive[]=$addsitetositereceive['reciveqty'];
	}
	
	
	/**************************************  Material Return *********************************************/
	$sqlsite_site1=DB_query("SELECT sum(ReturnQty) AS issueqty
	                    FROM  inv_material_return_details INNER JOIN inv_material_return 
				        ON inv_material_return.id=inv_material_return_details.parentId where sitecode='".$_REQUEST['site']."' and
						storecode='".$_REQUEST['store1']."' and Reqdate <= '".$fdate."' and  Reqdate <='".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addmrtov=DB_fetch_array($sqlsite_site1))
	{
	$issueqty[]=$addmrtov['issueqty'];
	
	}
	$tot1=array_sum($receive);
	 $tot2=array_sum($issueqty);
	if($tot1==$tot2)
	$qty=0;
	else
	 $qty=trim($tot1)-trim($tot2);
	
	//$qty=array_sum($receive)-array_sum($issueqty);
	/*******************************************  Opening ******************************************************/
	$sqlopen=DB_query("select reveive_date as date,mstid as itemid,stock as reciveqty
	from opening_stockitemwise  where site='".$_REQUEST['site']."'
	 and store='".$_REQUEST['store1']."' and reveive_date <='".$fdate."' 
	 and reveive_date <='".$toyrdate."' and mstid='".$_REQUEST['item']."'",$db);
	while($addopen=DB_fetch_array($sqlopen))
	{	
	//$qty1=$addopen['reciveqty']+$qty;
	$qty1=trim($addopen['reciveqty'])+trim($qty);
	//$vender=$s->getField('suppliers','id',$addmrn['vendor'],'vendor_name');
	$data[]=array('slipno'=>$addopen['slipno'],'itemid'=>$addopen['itemid'],
	'date'=>$fdate,'reciveqty'=>$qty1,'issueqty'=>'','doc'=>'','description'=>'Opening');
	}	
	}	
	
		
	
	
	/**************************************  MRN *********************************************/
	$sqlmrn=DB_query("select MRNDate as date,mst_itemid as itemid,reciveqty as reciveqty,MRNNo as slipno,ReceivedFrom as vendor
	,DocumentType,BillNo
	from addmrnqty inner join addmrn on addmrn.id=addmrnqty.issue_id  where site='".$_REQUEST['site']."'
	 and StoreCode='".$_REQUEST['store1']."' and MRNDate between '".$fdate."' 
	 and '".$toyrdate."' and mst_itemid='".$_REQUEST['item']."' and reciveqty!='0.00000'",$db);
	while($addmrn=DB_fetch_array($sqlmrn))
	{	
	$doc="MRN"."-".$addmrn['DocumentType']."-".$addmrn['BillNo'];
	$vender=$s->getField('suppliers','id',$addmrn['vendor'],'vendor_name');
	$data[]=array('slipno'=>$addmrn['slipno'],'itemid'=>$addmrn['itemid'],'date'=>$addmrn['date'],'reciveqty'=>$addmrn['reciveqty']    ,'issueqty'=>'','doc'=>$doc,'description'=>$vender);
	}	
	
	       
		   
	       /**************************************  Issue *********************************************/
	$sqlissue=DB_query("SELECT issuedate AS date ,mst_itemid AS itemid,issueqty AS issueqty ,issue_slipno as slipno,received_by,
	                    issueto FROM 
                        issueqty INNER JOIN addissue ON addissue.id=issueqty.issue_id where site='".$_REQUEST['site']."' and
						mst_storeid='".$_REQUEST['store1']."' 
						and issuedate between '".$fdate."' and '".$toyrdate."' and mst_itemid='".$_REQUEST['item']."' ",$db);	
	while($addissue=DB_fetch_array($sqlissue))
	{
	if($addissue['received_by']=='' || $addissue['received_by']==0)
	 $vender=$s->getField('contractor_master','id',$addissue['issueto'],'contractor_name');
	else
	 $vender=$s->getField('empmaster','id',$addissue['received_by'],'emp_name');
	$data[]=array('slipno'=> $addissue['slipno'], 'itemid' => $addissue['itemid'],'date' => $addissue['date']
	,'reciveqty'=>'null','issueqty'=>$addissue['issueqty'],'doc'=>'Issue Slip','description'=>$vender);
	
	}
			
	/**************************************  Receive *********************************************/
	$sqlreceive=DB_query("SELECT returndate AS date ,mst_itemid AS itemid,receiveqty AS reciveqty
	                    ,return_slipno as slipno,issue_slipno
	                    FROM  material_return_details INNER JOIN material_return 
				        ON material_return.id=material_return_details.parentId where site='".$_REQUEST['site']."' and
						store='".$_REQUEST['store1']."' and returndate between '".$fdate."' and '".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addreceive=DB_fetch_array($sqlreceive))
	{
	if($addreceive['receiveemp']=='' || $addreceive['receiveemp']=='0' )
	 $vender=$s->getField('contractor_master','id',$addreceive['receiveissue'],'contractor_name');
	else
	 $vender=$s->getField('empmaster','id',$addreceive['receiveemp'],'emp_name');
	$issuesilp=$s->getField('addissue','id',$addreceive['issue_slipno'],'issue_slipno');
	$data[]=array('slipno'=> $addreceive['slipno'],'itemid' => $addreceive['itemid'],'date' =>$addreceive['date']
	,'reciveqty'=>$addreceive['reciveqty'],'issueqty'=>'','doc'=>$issuesilp,'description'=>$vender);
	}
	
	
	/**************************************  site to site *********************************************/
	$sqlsite_site=DB_query("SELECT issuedate AS date ,mst_itemid AS itemid,issueqty AS issueqty
	                     ,issue_slipno as slipno,sitecode_to
	                    FROM  transfer_issue_details INNER JOIN transfer_issue 
				        ON transfer_issue.id=transfer_issue_details.transfer_issue_id where sitecode='".$_REQUEST['site']."' and
						fromstore='".$_REQUEST['store1']."' and issuedate between '".$fdate."' and '".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addsitetosite=DB_fetch_array($sqlsite_site))
	{
	$branch=$s->getField('locations','loccode',$addsitetosite['sitecode_to'],'locationname');
	$data[]=array('slipno'=> $addsitetosite['slipno'],'itemid' => $addsitetosite['itemid'],'date' =>$addsitetosite['date']
	,'issueqty'=>$addsitetosite['issueqty'],'reciveqty'=>'','doc'=>'Site To Site Issue','description'=>$branch);
	}
	
	
	/**************************************  site to site receive *********************************************/
	$sqlsite_site1=DB_query("SELECT MRNDate AS date ,mst_itemid AS itemid,reciveqty AS reciveqty
	                     ,MRNNo as slipno,ReceivedFrom
	                    FROM  transfer_receipt_details INNER JOIN transfer_receipt 
				        ON transfer_receipt.id=transfer_receipt_details.transfer_receipt_id
						 where sitecode='".$_REQUEST['site']."' and
						store='".$_REQUEST['store1']."' and MRNDate between '".$fdate."' and '".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addsitetositereceive=DB_fetch_array($sqlsite_site1))
	{
	$branch=$s->getField('locations','loccode',$addsitetositereceive['Issue_From'],'locationname');
	$data[]=array('slipno'=> $addsitetositereceive['slipno'],'itemid' => $addsitetositereceive['itemid'],'date' =>  
	  $addsitetositereceive['date'],'issueqty'=>'','reciveqty'=>$addsitetositereceive['reciveqty'],'doc'=>'Site To Site Receive','description'=>$branch);
	}
	
	
	/**************************************  Material Return *********************************************/
	$sqlsite_site1=DB_query("SELECT Reqdate AS date ,mst_itemid AS itemid,ReturnQty AS issueqty
	                     ,MRNNo as slipno,returnagainst
	                    FROM  inv_material_return_details INNER JOIN inv_material_return 
				        ON inv_material_return.id=inv_material_return_details.parentId where sitecode='".$_REQUEST['site']."' and
						storecode='".$_REQUEST['store1']."' and Reqdate between '".$fdate."' and '".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addmrtov=DB_fetch_array($sqlsite_site1))
	{
	
	$data[]=array('slipno'=> $addmrtov['slipno'],'itemid' => $addmrtov['itemid'],'date' =>  
	$addmrtov['date'],'issueqty'=>$addmrtov['issueqty'],'reciveqty'=>''
	,'doc'=>'Site To Site Issue','description'=>$addmrtov['returnagainst']);
	}
	/**************************************  Receive *********************************************/
		
	
	if(count($data)<=0)
	{
	
	
	$receive=array();
	$issueqty=array();	
	/**************************************  MRN *********************************************/
	
	$sqlmrn=DB_query("select sum(reciveqty) as reciveqty from addmrnqty 
	inner join addmrn on addmrn.id=addmrnqty.issue_id  where site='".$_REQUEST['site']."'
	 and StoreCode='".$_REQUEST['store1']."' and MRNDate <='".$fdate."' 
	 and MRNDate <='".$toyrdate."' and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addmrn=DB_fetch_array($sqlmrn))
	{	
	$receive[]=$addmrn['reciveqty'];
	}	
	
	       
		   
	       /**************************************  Issue *********************************************/
	$sqlissue=DB_query("SELECT sum(issueqty) AS issueqty FROM 
                        issueqty INNER JOIN addissue ON addissue.id=issueqty.issue_id where site='".$_REQUEST['site']."' and
						mst_storeid='".$_REQUEST['store1']."' 
						and issuedate <='".$fdate."' and issuedate <='".$toyrdate."' and mst_itemid='".$_REQUEST['item']."' ",$db);	
	while($addissue=DB_fetch_array($sqlissue))
	{
	$issueqty[]=$addissue['issueqty'];
	}
			
	/**************************************  Receive *********************************************/
	$sqlreceive=DB_query("SELECT sum(receiveqty) AS reciveqty
	                    FROM  material_return_details INNER JOIN material_return 
				        ON material_return.id=material_return_details.parentId where site='".$_REQUEST['site']."' and
						store='".$_REQUEST['store1']."' and returndate <='".$fdate."' and returndate <='".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addreceive=DB_fetch_array($sqlreceive))
	{
	$receive[]=$addreceive['reciveqty'];
	}
	
	
	/**************************************  site to site *********************************************/
	$sqlsite_site=DB_query("SELECT sum(issueqty) AS issueqty
	                     FROM  transfer_issue_details INNER JOIN transfer_issue 
				        ON transfer_issue.id=transfer_issue_details.transfer_issue_id where sitecode='".$_REQUEST['site']."' and
						fromstore='".$_REQUEST['store1']."' and issuedate <= '".$fdate."'  and  issuedate <='".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addsitetosite=DB_fetch_array($sqlsite_site))
	{
	$issueqty[]=$addsitetosite['issueqty'];
	}
	
	
	/**************************************  site to site receive *********************************************/
	$sqlsite_site1=DB_query("SELECT sum(reciveqty) AS reciveqty
	                      FROM  transfer_receipt_details INNER JOIN transfer_receipt 
				        ON transfer_receipt.id=transfer_receipt_details.transfer_receipt_id
						 where sitecode='".$_REQUEST['site']."' and
						store='".$_REQUEST['store1']."' and MRNDate <= '".$fdate."' and MRNDate <='".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addsitetositereceive=DB_fetch_array($sqlsite_site1))
	{
	$receive[]=$addsitetositereceive['reciveqty'];
	}
	
	
	/**************************************  Material Return *********************************************/
	$sqlsite_site1=DB_query("SELECT sum(ReturnQty) AS issueqty
	                    FROM  inv_material_return_details INNER JOIN inv_material_return 
				        ON inv_material_return.id=inv_material_return_details.parentId where sitecode='".$_REQUEST['site']."' and
						storecode='".$_REQUEST['store1']."' and Reqdate <= '".$fdate."' and  Reqdate <='".$toyrdate."' 
						and mst_itemid='".$_REQUEST['item']."'",$db);
	while($addmrtov=DB_fetch_array($sqlsite_site1))
	{
	$issueqty[]=$addmrtov['issueqty'];
	
	}
	$total15=array_sum($receive);
	$total16=array_sum($issueqty);
	if($total15==$total16)
	$qty=0;
	else
	$qty=trim($total15)-trim($total16);
	//$qty=array_sum($receive)-array_sum($issueqty);
	/*******************************************  Opening ******************************************************/
	$sqlopen=DB_query("select reveive_date as date,mstid as itemid,stock as reciveqty
	from opening_stockitemwise  where site='".$_REQUEST['site']."'
	 and store='".$_REQUEST['store1']."' and reveive_date <='".$fdate."' 
	 and reveive_date <='".$toyrdate."' and mstid='".$_REQUEST['item']."'",$db);
	while($addopen=DB_fetch_array($sqlopen))
	{	
	$qty1=$addopen['reciveqty']+$qty;
	//$vender=$s->getField('suppliers','id',$addmrn['vendor'],'vendor_name');
	$data[]=array('slipno'=>$addopen['slipno'],'itemid'=>$addopen['itemid'],
	'date'=>$addopen['date'],'reciveqty'=>$qty1,'issueqty'=>'','doc'=>'','description'=>'Opening');
	}	
	
	
	}
	
		
	
	foreach ($data as $key => $row1)
    {
    $volume[$key]= $row1['date'];
	$edition1[$key]=$row1['reciveqty'];
	}
    array_multisort($volume,SORT_ASC,$edition1,SORT_ASC,$data);
	?>

<div  style="height:800px">
 <table width="100%" border="1" cellpadding="5" cellspacing="1" bgcolor="#000000" style="border:#000000 solid 1px; background:#999999; font-size:12px;">
    <?php 

	
	
$Header="<tr>";
	 $Header.="<th width='5%'  class='jjrs_tablehead' ><strong>S.R</strong></th>";
      $Header.="<th width='5%'  class='jjrs_tablehead'><strong>Date</strong></th>";
      $Header.="<th width='31%'  class='jjrs_tablehead'><strong>Receiving from / issue to</strong></th>";
      $Header.="<th width='20%'  class='jjrs_tablehead'><strong>Transaction No.</strong></th>";
      $Header.="<th width='10%'  class='jjrs_tablehead'><strong>Against Bill/Challan </strong></th>";
      $Header.="<th width='9%'  class='jjrs_tablehead'><strong>Received Qty </strong></th>";
      $Header.="<th width='9%'  class='jjrs_tablehead'>Issued Qty</th>";
	   $Header.="<th width='9%'  class='jjrs_tablehead'>Bal Qty</th>";
  $Header.="</tr>";
	 echo $Header;
	if(count($data)>0)
	{
	//$var=0;
	$i=1;
	$j=0;
	$flag=0;
	$flag;
	$Count=0;
	//echo $Count=count($data);
  //  $t=0;
	foreach($data as $key=>$value)
	{
	//echo $Count=count($data);
	if($flag==0)
	{
	$k=22;
	}
//	 echo $flag."--flag........";
//	echo $j."--j........";
//	echo $k."--k.......";
//	 echo $i."--i<br /><br />";
	
	if($value['description']=='Opening')
	{
	$bgcolor='#999999';
	}
	else
	{
	$bgcolor='#FFFFFF';
	}
	 $j++; 
	 $flag;
	?>		
	<tr bgcolor="<?php echo $bgcolor; ?>">
	<td  class="jjrs_tablehead"><?php echo $i++;?></td>
	<td  class="jjrs_tablehead"><?php echo ConvertSQLDate($value['date']);?></td>
	<td  class="jjrs_tablehead"><?php echo $value['description'];?></td>
    <td  class="jjrs_tablehead"><?php echo $value['slipno'];?></td>
    <td  class="jjrs_tablehead"><?php echo $value['doc'];?></td>
     
      <td><?php  if($value['reciveqty']!='null') {  echo $value['reciveqty'];
	   $recieve[]=$value['reciveqty'];
	   }
	   else
	   {
	   echo "0";
	   $recieve[]=0;
	   }
	  //}
	  ?></td>
      <td><?php echo $value['issueqty']; $issue[]=$value['issueqty'];?></td>
      <td><?php
	         $total12=array_sum($recieve);
	            $total13=array_sum($issue);
				$opentotal=trim($total12)-trim($total13);
	   echo $opentotal; ?></td>
    </tr>
 <?php  

  
  // $x=$j%$k;
   //echo "x---".$x;
  //echo $k;
 if($j%$k==0)
 {
 $k=$k+27;
 $flag=$j;
?>
 </table>
 </div>
 </p>
 </div>
 </div>
 <div class="body_contain">
<div class="tab_div">

<?php echo $Header1; ?>
<div style="height:970px;">
 <table width="100%" border="1" cellpadding="5" cellspacing="1" bgcolor="#000000" style="border:#000000 solid 1px; background:#999999; font-size:12px;">
<?php echo $Header; ?>
<?php } 

 }
 ?>
  


<?php } else { ?>
<tr bgcolor="#FFFFFF">
<td  colspan="8"  class="jjrs_tablehead">No Records</td></tr>

<?php  } ?>
 </table>
 </div>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
       var e = document.getElementById(id);
	      e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
    }
  
</script>

