<link rel="stylesheet" href="css/new_mxerp.css">
<?php
$PageSecurity = 2;
include('includes/stockcalculation.php');
$title = _('View/Search Items') ;
include('includes/SQL_CommonFunctions.inc');
$_SESSION['modid']=$_REQUEST['modid'];
$_SESSION['frmid']=$_REQUEST['frmid'];
$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'],$_SESSION['ACGRoleId']);
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];

?>
<script language="javascript" type="text/javascript">
function get_itemsubgroup(str)
{
	if(str=="")
  {
  document.getElementById("sub_id").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("sub_id").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","item_subcategory.php?q="+str,true);
xmlhttp.send();
}

</script>
<?php 

$function_filter[]=$_SESSION['dealerid'];
$function_filter[]='';
$date55=date('Y-m-d');
$date22= strtotime(date("Y-m-d", strtotime($date55)) . " +0 day");
$date1= date("Y-m-d",$date22);
$function_filter[]=$date1;

if($_REQUEST['id']!='' && $_REQUEST['action']=='delete'  )
{
	  $delete_sql="delete from item_master where id='".$_REQUEST['id']."'";
	$d_res=DB_query($delete_sql,$db);
	
	if($_REQUEST['item_cat']=='FG')
	{
		$delete_color="Delete from item_color_master where item_master_id ='".$_REQUEST['id']."'";
		$r_res=DB_query($delete_color,$db);
	}
 	echo "<script>location.href='index.php?route=item_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['search'])
{
	$filter=array();
	
	if($_REQUEST['main_group']!='000')
	$filter[]="CategoryID = '".$_REQUEST['main_group']."'";
	if($_REQUEST['sub_group']!='000')
	$filter[]="SubCategoryID = '".$_REQUEST['sub_group']."'";
	if($_REQUEST['item_code']!='')
	$filter[]="StockID like '%".$_REQUEST['item_code']."%'";
	if($_REQUEST['item_name']!='')
	$filter[]="item_name like '%".$_REQUEST['item_name']."%'";
	
	if($filter!='')
	{
		$filter1=implode(" and ",$filter);
	}

	$sql="select * from item_master where $filter1 and CompanyId='".$_SESSION['ACGCompanyId']."' order by SubCategoryID";
}
else
{
	$sql="select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."' order by SubCategoryID";
}
$_SESSION['item_query1']=$sql;
 ?>

<div class="body_contain">
<div class="tab_div">

<h1>ITEMS</h1>
<form action="" method="post">
<table width="90%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;" align="center">
  <tr>
    <th class="tabledata1">Main Group</th>
    <td style="width:250px">
	<select name="main_group" id="main_group"
	    onchange="get_itemsubgroup(this.value)" style="width:100%">
	<option value="000">---Select---</option>
	<?php
	$query1=DB_query("select * from stockmaincategory  where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
	while($result1=DB_fetch_array($query1)) {
	?>
	<option value="<?php echo $result1['id'];?>"<?php echo ($_REQUEST['main_group']==$result1['id']?'selected':'')?>><?php echo $result1['stockmaincategoryname'];?></option>
	<?php } ?>
	</select>	</td>
    <th class="tabledata1"> Item Code</th>
    <td><input type="text" name="item_code" id="item_code"
    value="<?php echo $_REQUEST['item_code'];?>"  style="width:100%" /></td>
  </tr>
  <tr>
    <th class="tabledata1">Sub Group</strong></th>
    <td><div id="sub_id"><select name="sub_group" id="sub_group"  style="width:100%">
      <option value="000">---Select---</option>
      <?php
	  if($_REQUEST['main_group'])
	  {
	  $query2=DB_query("select * from stockcategory where stockmaincategory='".$_REQUEST['main_group']."'",$db);
	  }
	  else
	  {
	$query2=DB_query("select * from stockcategory",$db); 
	}
	while($result2=DB_fetch_array($query2)) {
	?>
      <option value="<?php echo $result2['id'];?>"<?php echo ($_REQUEST['sub_group']==$result2['id']?'selected':'')?>><?php echo $result2['categorydescription'];?></option>
      <?php } ?>
    </select></div></td>
    <th class="tabledata1">Item Name</th>
    <td><input type="text" name="item_name" id="item_name"
    value="<?php echo $_REQUEST['item_name'];?>"  style="width:100%" /></td>
  </tr>
</table>
<p align="center"><input type="submit" name="search" value="Search" /></p>

</form>
<p align="left">
<?php if($_SESSION['frmAdd']=='1'){?>

<a href="index.php?route=crm_item_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>" class="search" style="text-decoration:none;"><input type='button' value='Add New' class="search" /></a><?php } ?>

<a href="itemlistprint.php" class="search" style="text-decoration:none;"><input type='button' value='Print' class="search" /></a></p>

<form action="" method="post">
 
   
<table width="100%" border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse; border:#666666 solid 1px;">
      <tr>
      <td class="tabledata">Part No</td>
     <td class="tabledata">Part Description</td>
      <td class="tabledata">Finished Qty</strong></td>
	 <td class="tabledata">Delivery Days</strong></td>
	 <td class="tabledata">Price</strong></td>
     <td class="tabledata">View</strong> </td>
      <td class="tabledata"> Edit</strong></td>
      <td class="tabledata"> Delete</strong> </td>
    </tr
><?php 
 	$result=DB_query($sql,$db);
	$i=1;
	if(DB_num_rows($result)>0)
	{
	while($myrow=DB_fetch_array($result))
	{
	
	$op=openingBalance($function_filter,$myrow['id']);
$in_1=receivedMRN($function_filter,$myrow['id']);
$out_1=issueSlip($function_filter,$myrow['id']);
$out_2=issueSiteToSite($function_filter,$myrow['id']);		
$in_2=receivedSiteToSite($function_filter,$myrow['id']);
$out_3=issueMatarialReturn($function_filter,$myrow['id']);
$in_3=receivedReturn($function_filter,$myrow['id']);	
$out_4=Rgpchallan($function_filter,$myrow['id']);
$out_5=Nrgp($function_filter,$myrow['id']);
$in_4=Rgpreturn($function_filter,$myrow['id']);	 
$in_5=FinishedMR($function_filter,$myrow['id']);
$in_6=dispatchreturnsaleorder($function_filter,$myrow['id']);
$out_6=dispatchsaleorder($function_filter,$myrow['id']);
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5+$in_6);
$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5+$out_6);
$tot=trim($invalue)-trim($outvalue);
$total_current=$tot;
	
	
	
	
   ?> 
<tr bgcolor="#c1c1c1">
    <td width="10%"><?php echo $myrow['StockID'];?></td>
	 <td width="30%"><?php echo $myrow['item_name'];?></td>
    <td width="30%"><?php echo $total_current;?></td>
	  <td width="30%"><?php ?></td>
	   <td width="30%"><?php echo $myrow['net_rate'];?></td>
	
	
	
    <td width="10%"><?php if($_SESSION['frmView']=='1'){?><a href="index.php?route=crm_item_master&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $myrow['id'];?>&action=view">View</a><?php }else{echo "No Permission";}?></td>
	<td width="10%"><?php if($_SESSION['frmEdit']=='1'){?><a href="index.php?route=crm_item_master&<?php  echo $rurl;?>&id=<?php echo $myrow['id'];?>&action=edit"> <img src="images/icon-edit.png" width="10" height="10" /></a><?php }else{echo "No Permission";}?></td>
	<td width="10%"><?php if($_SESSION['frmDelete']=='1'){?><a href="index.php?route=item_list&<?php  echo $rurl;?>&id=<?php echo $myrow['id'];?>&action=delete" onClick="return confirm('Are you sure you want to delete this Item record?');"> <img src="images/Icon_Delete.png"  width="10" height="10"  /></a><?php } else{echo "No Permission";}?></td>
  </tr>
  <?php $i++;} 
  }
  else
  {?>
  <tr>
  <td colspan="7"><h3 align="center"><font color="#FF0000">No Record Found!</font></h3>
  </td>
  </tr>
  <?php 	
  }?>
</table>
 
</form>
</div></div>




<?php 
//include('includes/footer.inc');
?>