<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1><?php echo  $page_title; ?></h1>
<?php include('POModule/Class-ItemMaster.php');?>

<script>
function displatbranch()
{
	if(document.getElementById("getbranchwise").style.display!='block')
	{
	document.getElementById("getbranchwise").style.display="block";
	document.getElementById("getvendorwise").style.display="none";
	document.getElementById("getitem").style.display="none";
	document.getElementById("pty").style.display="none";
	document.getElementById("ven").style.display="none";
	}
}

function displayvendor()
{
	if(document.getElementById("getvendorwise").style.display!='block')
	{
	document.getElementById("getvendorwise").style.display="block";
	document.getElementById("getbranchwise").style.display="none";
	document.getElementById("getitem").style.display="none";
	document.getElementById("pr").style.display="none";
	document.getElementById("pty").style.display="none";
	}
}


function displayitem()
{
	if(document.getElementById("getitem").style.display!='block')
	{
	document.getElementById("getitem").style.display="block";
	document.getElementById("getbranchwise").style.display="none";
	document.getElementById("getvendorwise").style.display="none";
	document.getElementById("pr").style.display="none";
	document.getElementById("ven").style.display="none";
	}
}
</script>


<table width="100%" cellpadding="3" cellspacing="0" border="0">
	<tr class="row1">
		<td width="5%" align="right"><input name="period" type="radio" value="party" <?php if($_REQUEST['SearchBranch']=='Search'){ echo 'checked' ;}else{ }?> onClick="displatbranch(this.value)"/></td>
		<td width="20%">Branch Wise</td>
		<td width="5%" align="right"><input name="period" type="radio" value="vend" <?php if($_REQUEST['SearchVendor']=='Search'){ echo 'checked' ;}else{ }?> onClick="displayvendor(this.value)"/></td>
		<td width="20%">Vendor Wise</td>
		<td width="5%" align="right"><input name="period" type="radio" value="tech" <?php if($_REQUEST['SearchItem']=='Search'){ echo 'checked' ;}else{ }?> onClick="displayitem(this.value)"/></td>
		<td>Item Wise</td>
	</tr>
</table>
<br>

<div style="display:none" id="getbranchwise">
<form action="" method="post">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	<td width="13%" align="right">Branch</td>
	<td width="20%">
<?php
if($_SESSION['AssignedBranch']!=''){	  	
$ss1="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
$site_sql1=DB_query($ss1,$db);
}
else
{
$ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
$site_sql1=DB_query($ss1,$db);
}
?>
	
	<select name="site" id="site" onChange="showsitename160(this.value)">
	<option value="">Select Site</option>
	<?php 
	
	
	while($site_row = DB_fetch_array($site_sql1))
	{
	$p='';
	if($site_row['loccode'] == $_POST['site'])	
	$p="selected";
	?>
	<option value="<?php echo $site_row['loccode']; ?>" <?php echo $p;?>><?php echo $site_row['locationname']; ?></option>
	<?php } ?>
	</select>
	</td>
	<td width="13%" align="right">From</td>
	<td width="20%"><input type="text" name="fromdate" value="<?php echo $_POST['fromdate'];?>" class="datepicker" ></td>
	<td width="13%" align="right">To</td>
	<td><input type="text" name="todate" value="<?php echo $_POST['todate'];?>" class="datepicker"></td>
</tr>
<tr class="row1">
	<td align="center" colspan="6"><input type="submit" name="SearchBranch" class="search" value="Search"></td>
	</tr>
</table>
</form>
</div>


<div style="display:none" id="getvendorwise">
<form action="" method="post">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	<td width="13%" align="right">Branch</td>
	<td width="20%">
	<?php
	if($_SESSION['AssignedBranch']!='')
	  {	  	
  $ss1="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql1=DB_query($ss1,$db);
	  }
	  else
	  {
		$ss1="Select loccode,locationname from locations where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$site_sql1=DB_query($ss1,$db);
	  }
	?>
	<select name="site12" id="site12">
	<option value="">Select Site</option>
	<?php while($site_row = DB_fetch_array($site_sql1)){
	$p='';
	if($site_row['loccode'] == $_POST['site12'])	
	$p="selected";?>
	<option value="<?php echo $site_row['loccode']; ?>" <?php echo $p;?>><?php echo $site_row['locationname']; ?></option>
	<?php } ?>
	</select>
	</td>
	<td width="13%" align="right">From</td>
	<td width="20%"><input type="text" name="fromdate12" value="<?php echo $_POST['fromdate12'];?>" class="datepicker" ></td>
	<td width="13%" align="right">To</td>
	<td ><input type="text" name="todate12" value="<?php echo $_POST['todate12'];?>" class="datepicker"></td>
</tr>
<tr class="row1">
	<td width="13%" align="right">Vendor</td>
	<td>
	<select name="vendor" id="vendor">
		<option value="0">Select Vendor</option>
	<?php $SQLVen=DB_query("Select * from suppliers",$db); 
	while($GetVendor=DB_fetch_array($SQLVen)){
	$sel1='';
	if($_REQUEST['vendor']==$GetVendor['id'])
	$sel1='selected';?>
		<option value="<?php echo $GetVendor['id']; ?>"<?php echo $sel1; ?>><?php echo str_replace(array("M/S","M/s"),'',$GetVendor['vendor_name']); ?></option>
		
		<?php }?> 
	</select>
	</td>
	<td colspan="4"></td>
</tr>
<tr class="row1">
	<td align="center" colspan="6"><input type="submit" name="SearchVendor" class="search" value="Search"></td>
	</tr>
</table>
</form>
</div>

<div style="display:none" id="getitem">
<form action="" method="post">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr class="row1">
	<td width="13%" align="right">Branch</td>
	<td width="20%"><select name="site123" id="site123">
	<option value="">Select Site</option>
	<?php 		
	$site_sql = "Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	$site_result = DB_query($site_sql,$db);
	while($site_row = DB_fetch_array($site_result))
	{
	$p='';
	if($site_row['loccode'] == $_POST['site123'])	
	$p="selected";
	?>
	<option value="<?php echo $site_row['loccode']; ?>" <?php echo $p;?>><?php echo $site_row['locationname']; ?></option>
	<?php } ?>
	</select>
	</td>
	<td width="13%" align="right">From</td>
	<td width="20%"><input type="text" name="fdate" value="<?php echo $_POST['fdate'];?>" class="datepicker" ></td>
	<td width="13%" align="right">To</td>
	<td><input type="text" name="tdate" value="<?php echo $_POST['tdate'];?>" class="datepicker"></td>
</tr>
<tr class="row1">
	<td align="right">Item</td>
	<td id="itemid">
	<select name="itemdata" id="itemdata">
	<option value="">Select ITEM</option>
	<?php 
	$itemSql=DB_query("Select id,StockID,item_name from item_master",$db);
	while($itemRow=DB_fetch_array($itemSql))
	{?>
	<option value="<?php echo $itemRow['id'];?>"<?php echo($_REQUEST['itemdata']==$itemRow['id']?'selected':'')?>><?php echo $itemRow['item_name']." - ".$itemRow['StockID'];?></option>
	<?php 	
	}
	?>    	
	</select></td>
	<td colspan="4"></td>
	</tr>
	<tr class="row1">
	<td align="center" colspan="6"><input type="submit" name="SearchItem" value="Search" class="search" /></td>
	</tr>
</table>
</form>
</div>


<?php 
if($_REQUEST['SearchBranch']){
	$fromdate=FormatDateForSQL($_REQUEST['fromdate']);
	$todate=FormatDateForSQL($_REQUEST['todate']);
	
	if($_REQUEST['site']!='')
	{
		$filter[]="branch='".$_REQUEST['site']."'";
	}
	
	if($fromdate!='' && $todate!='')
	{
		$filter[]="date between '".$fromdate."' and '".$todate."'";
	}
	if($filter!='')
	{
		$filter1=implode(" and ",$filter);
        $sql2 ="SELECT * FROM rgp_tab where $filter1";
  	}
  $_SESSION['purch_reg1']=$sql2 ;  
?>
<?php } ?>


<?php 
if($_REQUEST['SearchVendor']){
	$fromdate12=FormatDateForSQL($_REQUEST['fromdate12']);
	$todate12=FormatDateForSQL($_REQUEST['todate12']);
	
	if($_REQUEST['site12']!='')
	{
		$filter[]="branch='".$_REQUEST['site12']."'";
	}
	
	if($fromdate12!='' && $todate12!='')
	{
		$filter[]="date between '".$fromdate12."' and '".$todate12."'";
	}
	
	if($_REQUEST['vendor']!='0')
	{
		$filter[]="supplier='".$_REQUEST['vendor']."'";
	}
	
	if($filter!='')
	{
		$filter1=implode(" and ",$filter);
        $sql2 ="SELECT * FROM rgp_tab where $filter1";
  	}
  
  $_SESSION['purch_reg1']=$sql2 ;  
?>
<?php } ?>


<?php if($_REQUEST['SearchItem']){
	$fdate=FormatDateForSQL($_REQUEST['fdate']);
	$tdate=FormatDateForSQL($_REQUEST['tdate']);
	
	if($_REQUEST['site123']!='')
	{
		$filter[]="branch='".$_REQUEST['site123']."'";
	}
	
	if($fromdate12!='' && $todate12!='')
	{
		$filter[]="date between '".$fdate."' and '".$tdate."'";
	}
	if($filter!='')
	{
		$filter1=implode(" and ",$filter);
        $sql2 ="SELECT * FROM rgp_tab where $filter1";
  	}
  
  $_SESSION['purch_reg1']=$sql2 ;  
?>
<?php }?>

<?php if($_REQUEST['SearchBranch']){ ?>
<script>document.getElementById("getbranchwise").style.display="block";</script>
<div id="pr">

<?php 
if($_REQUEST['site']!=''){
$Branch=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site']."'",'locationname');
$message="Branch <u><span class='fntBig'>".$Branch."</span></u> From Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['fromdate'])."</span></u> To Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['todate'])."</span></u>";
}
?>
<p align="center"><strong><?php echo $message; ?></strong> <a href="RGP_register-print.php?site1=<?php echo $_REQUEST['site'];?>&todate=<?php echo $_REQUEST['todate'];?>&fromdate=<?php echo $_REQUEST['fromdate'];?>" target="_blank" class="search" style="float:right;">Print</a>
</p>

<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
<tr>
	<th width="3%">S. No.</th>   
	<th width="8%">RGP No.</th>
	<th width="7%">Date</th>
	<th>Supplier</th>
	<th width="7%">Expected Date</th>
	<th width="7%">Form No.</th>
	<th width="180">Item Name</th>
	<th width="50">UOM</th>
	<th width="60">Qty.</th>
	<th width="120">Reason</th>
	<th width="90">Rate</th>
	<th width="90">Receive</th>
</tr>
  <?php
$i=1;
$res = DB_query($sql2,$db);
while($row = DB_fetch_array($res)){ ?>
  <tr>
    <td><?php echo $i++;?></td>
    <td><?php  echo $row['rgp_no'];?></td>
    <td><?php  echo ConvertSQLDate($row['date']);?></td>
	<td><?php  echo $s->GetFieldValue('suppliers',"id='".$row['supplier']."'",'vendor_name');?></td>
	<td><?php  echo ConvertSQLDate($row['expected_date']);?></td>
	<td><?php  echo $row['form_no'];?></td>
	<td colspan="6" valign="top" style="margin:0px; padding:0px;">
	<div id="amc-tB"><table width="100%" border="0" cellpadding="3" cellspacing="0">
<?php 
$ItemSQL=DB_query("select * from rgp_tab_details where parent_id='".$row['id']."'",$db);
 $numrow1=DB_num_rows($ItemSQL);
if(DB_num_rows($ItemSQL)>0){
while($details_row=DB_fetch_array($ItemSQL)){
$itemname1=DB_query("select * from item_master where id='".$details_row['mst_itemid']."'",$db);
$itemname2=DB_fetch_array($itemname1);
$item1=$itemname2['item_name']; 
$UnitName=$s->GetFieldValue('unitsofmeasure',"unitid='".$itemname2['unit']."'",'unitname');
$reason=$s->GetFieldValue('job_work_master',"id='".$details_row['job_process']."'",'jobwork_name');

   $sql2=DB_query("select * from  rgp_tab_details where parent_id='".$details_row['id']."'",$db);
   $numdata=DB_num_rows($sql2);
   $sql3=DB_query("select * from  rgp_tab_details where parent_id='".$details_row['id']."' and status='N'",$db);
    $numdata1=DB_num_rows($sql3);
     $sql4=DB_query("select * from  rgp_tab_details where parent_id='".$details_row['id']."' and status='P'",$db);
   $numdata2=DB_num_rows($sql4);
   if($numdata2>=1)
   $status="Partial Received";
   else if($numdata==$numdata1)
   $status="Pending";
   else
   $status="Received";  
?>
		<tr>
            <td width="180"><?php echo $item1; ?></td>
            <td width="50"><?php echo $UnitName; ?></td>
            <td width="60"><?php echo $details_row['qty'] ?></td>
			<td width="120"><?php echo $reason; ?></td>
            <td width="90"><?php echo $details_row['job_rate']; ?></td>
			<td width="90"><?php echo  $status; ?></td>
		</tr>
          <?php } ?>
          <?php } ?>
        </table></div></td>
   </tr>
<?php  $sno++; } if($numrow1>0) { ?>
   <!-- <tr bgcolor="#e7e7e7" style="height: 25px">
      <td><strong></strong></td>
     <td>&nbsp;</td>
<?php if($_REQUEST['site']=='') { ?> <td>&nbsp;</td><?php } ?>
       <td>&nbsp;</td>
	  <td><strong>
	     <td><strong>Total</strong></td>
       <td><strong>&nbsp;<?php echo $a[]=array_sum($issueqty)?></strong></td>
      <td>&nbsp;</td>
    </tr> -->
<?php } else { ?>
	   <tr>
      <td colspan="12" align="center"><strong>No Records</strong></td>
    </tr>
<?php } ?>     
</table>
</div>
<?php  }else{ ?>
<script>document.getElementById("getbranchwise").style.display="none";</script>
<?php }?>

<?php if($_REQUEST['SearchVendor']){?>
<script>document.getElementById("getvendorwise").style.display="block";</script>
<div id="ven">

<?php 
if($_REQUEST['site12']!=''){
$Branch=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site12']."'",'locationname');
$message="Branch <u><span class='fntBig'>".$Branch."</span></u> From Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['fromdate12'])."</span></u> To Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['todate12'])."</span></u>";
}
if($_REQUEST['vendor']!='0'){
$vendorName=$s->GetFieldValue('suppliers',"id='".$_REQUEST['vendor']."'",'vendor_name');
$message="Vendor <u><span class='fntBig'>".$vendorName."</span></u> From Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['fromdate12'])."</span></u> To Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['todate12'])."</span></u>";
}
if($_REQUEST['site12']!='' && $_REQUEST['vendor']!='0')
{
$Branch=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site12']."'",'locationname');
$vendorName=$s->GetFieldValue('suppliers',"id='".$_REQUEST['vendor']."'",'vendor_name');
$message="Branch <u><span class='fntBig'>".$Branch."</span></u> And Vendor <u><span class='fntBig'>".$vendorName."</span></u> From Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['fromdate12'])."</span></u> To Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['todate12'])."</span></u>";
}
?>
<p align="center"><strong>Showing Records of <?php echo $message; ?></strong> <a href="RGP_register-print.php?site12=<?php echo $_REQUEST['site12'];?>&todate12=<?php echo $_REQUEST['todate12'];?>&fromdate12=<?php echo $_REQUEST['fromdate12'];?>&vendor=<?php echo $_REQUEST['vendor']; ?>" target="_blank" class="search" style="float:right;">Print</a>
</p>

<table width="100%" border="0"  cellspacing="0" cellpadding="3" class="thborder">
  <tr>
    <th width="6%">S. No.</th>   
    <th width="11%">RGP No.</th>
    <th width="20%">Date</th>
<?php if($_REQUEST['site12']==''){ ?>
	<th>Branch</th>
<?php } ?>
<?php if($_REQUEST['vendor']=='0'){ ?>
	<th width="12%">Supplier</th>
<?php } ?>
	<th width="12%">Form No.</th>
    <th width="120">Item Name</th>
    <th width="50">UOM</th>
    <th width="60">Qty.</th>
	<th width="100">Reason</th>
    <th width="90">Rate</th>
	<th width="90">Receive</th>
  </tr>
<?php
$i=1;
$res = DB_query($sql2,$db);
while($row = DB_fetch_array($res)){ ?>
  <tr>
    <td><?php echo $i++;?></td>
    <td><?php  echo $row['rgp_no'];?></td>
    <td><?php  echo ConvertSQLDate($row['date']);?></td>
<?php if($_REQUEST['site12']==''){ ?>
	<td><?php  echo $s->GetFieldValue('locations',"loccode='".$row['branch']."'",'locationname');?></td>
<?php } ?>
<?php if($_REQUEST['vendor']=='0'){ ?>
	<td><?php  echo $s->GetFieldValue('suppliers',"id='".$row['supplier']."'",'vendor_name');?></td>
<?php } ?>
<td><?php  echo ConvertSQLDate($row['expected_date']);?></td>
	<td><?php  echo $row['form_no'];?></td>
	<td colspan="6" valign="top" style="margin:0px; padding:0px;">
	<div id="amc-tab"><table width="100%" border="0" cellpadding="3" cellspacing="0">
<?php 
$ItemSQL=DB_query("select * from rgp_tab_details where parent_id='".$row['id']."'",$db);
 $numrow1=DB_num_rows($ItemSQL);
if(DB_num_rows($ItemSQL)>0){
while($details_row=DB_fetch_array($ItemSQL)){
$itemname1=DB_query("select * from item_master where id='".$details_row['mst_itemid']."'",$db);
$itemname2=DB_fetch_array($itemname1);
$item1=$itemname2['item_name']; 
$UnitName=$s->GetFieldValue('unitsofmeasure',"unitid='".$itemname2['unit']."'",'unitname');
$reason=$s->GetFieldValue('job_work_master',"id='".$details_row['job_process']."'",'jobwork_name');
?>
		<tr>
            <td width="120"><?php echo $item1; ?></td>
            <td width="50"><?php echo $UnitName; ?></td>
            <td width="60"><?php echo $details_row['qty'] ?></td>
			<td width="100"><?php echo $reason; ?></td>
            <td width="90"><?php echo $details_row['job_rate']; ?></td>
			<td width="90"><?php if($row['status']=='Y'){echo 'Y';}else{echo 'N';} ?></td>
		</tr>
          <?php } ?>
       
          <?php } ?>
        </table></div></td>
   </tr>
    <?php  $sno++; } if($numrow1>0) { ?>
   
   <!-- <tr bgcolor="#e7e7e7" style="height: 25px">
      <td><strong></strong></td>
     <td>&nbsp;</td>
	 <?php if($_REQUEST['site']=='') { ?> <td>&nbsp;</td><?php } ?>
       <td>&nbsp;</td>
	  <td><strong>
	     <td><strong>Total</strong></td>
       <td><strong>&nbsp;<?php echo $a[]=array_sum($issueqty)?></strong></td>
     
      <td>&nbsp;</td>
     
      
    </tr> -->
   
      <?php } else { ?>
	   <tr>
      <td colspan="13" align="center"><strong>No Records</strong></td>
    </tr>
      <?php } ?>     
</table>
</div>
<?php  }else{ ?>
<script>document.getElementById("getvendorwise").style.display="none";</script>
<?php }?>

<?php if($_REQUEST['SearchItem']){ ?>
<script>document.getElementById("getitem").style.display="block";</script>
<div id="pty">

<?php 
if($_REQUEST['site123']!=''){
$Branch=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site123']."'",'locationname');
$message="Branch <u><span class='fntBig'>".$Branch."</span></u> From Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['fdate'])."</span></u> To Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['tdate'])."</span></u>";
}
if($_REQUEST['itemdata']!='' && $_REQUEST['site123']!=''){
$Item=$s->GetFieldValue('item_master',"id='".$_REQUEST['itemdata']."'",'item_name');
$Branch=$s->GetFieldValue('locations',"loccode='".$_REQUEST['site123']."'",'locationname');
$message="Branch <u><span class='fntBig'>".$Branch."</span></u> And <u><span class='fntBig'>".$Item."</span></u> From Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['fdate'])."</span></u> To Date <u><span class='fntBig'>".ConvertSQLDate($_REQUEST['tdate'])."</span></u>";
}
?>

<p align="center"><strong>Showing Records of <?php echo $message; ?></strong> <a href="RGP_register-print.php?site123=<?php echo $_REQUEST['site123'];?>&itemdata=<?php echo $_REQUEST['itemdata'];?>&tdate=<?php echo $_REQUEST['tdate'];?>&fdate=<?php echo $_REQUEST['fdate'];?>&vendor=<?php echo $_REQUEST['vendor'];?>" target="_blank" class="search" style="float:right;">Print</a>
</p>

<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
  <tr>
    <th width="6%">S.N</th>   
    <th width="11%">RGP No</th>
    <th width="7%">Date</th>
<?php if($_REQUEST['site123']==''){ ?>
	<th>Branch</th>
<?php } ?>
	<th width="12%">Supplier</th>
	<th width="10%">Form No.</th>
<?php if($_REQUEST['itemdata']==''){ ?>
    <th width="120">Item Name</th>
<?php } ?>
    <th width="50">UOM</th>
    <th width="60">Qty.</th>
	<th width="100">Reason</th>
    <th width="90">Rate</th>
	<th width="90">Receive</th>
  </tr>
  <?php
$i=1;
$res = DB_query($sql2,$db);
while($row = DB_fetch_array($res)){ ?>
  <tr>
    <td><?php echo $i++;?></td>
    <td><?php  echo $row['rgp_no'];?></td>
    <td><?php  echo ConvertSQLDate($row['date']);?></td>
<?php if($_REQUEST['site123']==''){ ?>
	<td><?php  echo $s->GetFieldValue('locations',"loccode='".$row['branch']."'",'locationname');?></td>
<?php } ?>
	<td><?php  echo $s->GetFieldValue('suppliers',"id='".$row['supplier']."'",'vendor_name');?></td>
	<td><?php  echo $row['form_no'];?></td>
	<td colspan="6" valign="top" style="margin:0px; padding:0px;"><div id="amc-tab"><table width="100%" border="0" cellpadding="3" cellspacing="0">
<?php 
if($_REQUEST['itemdata']!='')
{
	$AKS="select * from rgp_tab_details where parent_id='".$row['id']."' and mst_itemid='".$_REQUEST['itemdata']."'";
}
else
{
	$AKS="select * from rgp_tab_details where parent_id='".$row['id']."'";
}
$ItemSQL=DB_query($AKS,$db);
 $numrow1=DB_num_rows($ItemSQL);
if(DB_num_rows($ItemSQL)>0){
while($details_row=DB_fetch_array($ItemSQL)){
$itemname1=DB_query("select * from item_master where id='".$details_row['mst_itemid']."'",$db);
$itemname2=DB_fetch_array($itemname1);
$item1=$itemname2['item_name']; 
$UnitName=$s->GetFieldValue('unitsofmeasure',"unitid='".$itemname2['unit']."'",'unitname');
$reason=$s->GetFieldValue('job_work_master',"id='".$details_row['job_process']."'",'jobwork_name');
?>
<tr>
<?php if($_REQUEST['itemdata']==''){ ?>
            <td width="120"><?php echo $item1; ?></td>
<?php } ?>
            <td width="50"><?php echo $UnitName; ?></td>
            <td width="60"><?php echo $details_row['qty'] ?></td>
			 <td width="100"><?php echo $reason; ?></td>
            <td width="90"><?php echo $details_row['job_rate']; ?></td>
			<td width="90"><?php if($row['status']=='Y'){echo 'Y';}else{echo 'N';} ?></td>
</tr>
          <?php } ?>
       
          <?php } ?>
        </table></div></td>
   </tr>
    <?php  $sno++; } if($numrow1>0) { ?>
   
   <!-- <tr bgcolor="#e7e7e7" style="height: 25px">
      <td><strong></strong></td>
     <td>&nbsp;</td>
	 <?php if($_REQUEST['site']=='') { ?> <td>&nbsp;</td><?php } ?>
       <td>&nbsp;</td>
	  <td><strong>
	     <td><strong>Total</strong></td>
       <td><strong>&nbsp;<?php echo $a[]=array_sum($issueqty)?></strong></td>
     
      <td>&nbsp;</td>
     
      
    </tr> -->
   
      <?php } else { ?>
	   <tr>
      <td colspan="13" align="center"><strong>No Records</strong></td>
    </tr>
      <?php } ?>     
</table>
</div>
<?php  }else{ ?>
<script>document.getElementById("getitem").style.display="none";</script>
<?php }?>

</div>
</div>

