<?php $PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/SQL_CommonFunctions.inc');
include('includes/function_lib.php');
//include('includes/stockcalculation.php');
include('includes/stockcalculation.php');

//$sitesname = $_REQUEST['site'];
$function_filter[]=$sitesname;
$function_filter[]='';
//$data_date=explode('/',$_REQUEST['date']);
					     // $date55=$data_date[2].'-'.$data_date[1].'-'.$data_date[0];
					     // $date22= strtotime(date("Y-m-d", strtotime($date55)) . " +0 day");
                            // $date1= date("Y-m-d",$date22);
//$function_filter[]=ConvertSQLDate($_REQUEST['qutationdate']);

?>
<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<h2 align="center">Search Cost Category Code</h2>
<form>
<table width="100%" border="0" style="border:1px solid #333333;" align="right" cellspacing="0" cellpadding="3">
<tr>
	 <td><strong>Parent Category </strong></td>
	<td>
		<select style="width:70px;" name="under_group" id="under_group">
		<option value="0">Select</option>
		<?php $sql="select * from account_cost_category where parent_id='0' ";
		$query=DB_query($sql,$db);
		while($row1=DB_fetch_array($query))
		{
      $t1='';
      if($row1['id']==$_REQUEST['under_group'])
       $t1="selected";
			?>
			<option value="<?php echo $row1['id']; ?>" <?php echo $t1; ?>><?php echo $row1['category_name']; ?></option>
		<?php }	?>  
      	</select>
    </td> 
    <td><strong>Category Code</strong></td>
	<td><input name="asset_code" type="text" id="asset_code" style="width:70px;"  /></td>
	<td><strong>Category Name</strong></td>
	<td><input name="asset_name" type="text" id="asset_name" style="width:70px;"  /></td>
</tr>
<tr>
   <td colspan="6" align="center">
		<input name="site" type="hidden" id="site" style="width:70px;" value="<?php echo $_REQUEST['site']; ?>"  />
		<input type="button" onclick="getdataforSearch()" value="Search"></td> 
</tr>
</table>
<br />
<br /><br />

<br /><br />


<div  id="ItemListDiv">
<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
  <tr>
	  	<th style="text-align:center"><strong>Select</strong></th>
	    <th style="text-align:center"><strong>Code</strong></th>
		<th style="text-align:center"><strong>Category Name</strong></th>
	</tr>
	<?php  
	
    /*if(isset($_REQUEST['Search']))
    {
    	$filter=array();

     if($_REQUEST['code']!='')	
     	$filter[]="code like '%".$_REQUEST['code']."%' or code like '%".$_REQUEST['code']."%' ";
     if($_REQUEST['category_name']!='')	
     	$filter[]="category_name like '%".$_REQUEST['category_name']."%' or category_name like '%".$_REQUEST['name']."%' ";
       if($_REQUEST['parent']!='0')	
     	$filter[]="parent_id='".$_REQUEST['parent']."'";
    }	
    	
    if(!empty($filter))
    	$filter1=implode(" and ",$filter);
    
 if(!empty($filter))
  {
  	//echo "Select * from account_cost_category where CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 ";
	$sql=DB_query("Select * from account_cost_category where and $filter1 and CompanyId='".$_SESSION['ACGCompanyId']."' and parent_id!='0' ",$db);
	
  }
 else
 {
 	 //echo "Select * from account_cost_category where CompanyId='".$_SESSION['ACGCompanyId']."' ";
      $sql=DB_query("Select * from account_cost_category where CompanyId='".$_SESSION['ACGCompanyId']."' and parent_id!='0' ",$db);
  } */
   $i=0;
   $sql_parent=DB_query("Select * from account_cost_category where CompanyId='".$_SESSION['ACGCompanyId']."' and parent_id='0' ",$db);
    
    while($result_parent=DB_fetch_array($sql_parent))
    {
    	?>
    	<tr>
	  	   <td style="text-align:left" colspan="3"><strong><?php echo $result_parent['category_name']; ?></strong></th>
	    </tr>


 <?php 
       $sql=DB_query("Select * from account_cost_category where CompanyId='".$_SESSION['ACGCompanyId']."' and parent_id='".$result_parent['id']."' and parent_id!='0' ",$db);

	 ?>

<?php	
	  
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
		 $parameter=$myrow['id'];
		 $parent=$myrow['parent_id'];
		 
		
		    /*	$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=MaterialConReceived($function_filter,$myrow['id']);
				$out_6=MaterialConIssue($function_filter,$myrow['id']);
				$in_7=PhysicalStockPlus($function_filter,$myrow['id']);
				$out_7=PhysicalStockMinus($function_filter,$myrow['id']);
				$out_8=dispatchIssue($function_filter,$myrow['id']);
				$out_9=jobWorkChallan57Issue($function_filter,$myrow['id']);
				$in_8=jobWorkChallan57Received($function_filter,$myrow['id']);
				$in_9=directPurchase($function_filter,$myrow['id']);
				$in_10=saleReturn($function_filter,$myrow['id']);
				$out_10=invoice($function_filter,$myrow['id']);
				$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8+$in_9 +$in_10);
				$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5 + $out_6 + $out_7 + $out_8 + $out_9+$out_10);
				$tot=$invalue-$outvalue;
				$stockallitems=$tot; */

			 	$total_current=$tot;		 
		     	$data1='';
		 
  ?>
    <tr bgcolor="#CCCCCC">
	      <td  ><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>"
	       onclick="getItemsList(this,'<?php echo $parameter;?>','<?php echo htmlentities($myrow['code'], ENT_QUOTES);?>','<?php  echo string_sanitize($myrow['category_name']); ?> ','<?php echo $i; ?>','<?php echo $s->getField('account_cost_category','id',$parent,'category_name')  ?>')"/></td>
	      <td><strong><?php echo $myrow['code'];?></strong></td>
		  <td><?php echo  $myrow['category_name'];?></td>
		  <!-- <td><?php $parent=$myrow['parent_id']; echo $s->getField('account_cost_category','id',$parent,'category_name') ?></td> -->
    </tr>
<?php $i++;} } }?>
 </table>
</div>
</form>
</table>

<script language="javascript" type="text/javascript">





function getdata1(str)
{  





	var maincat =$('#srch_cateory').val();
	var subcat =$('#srch_subcateory').val();
	var srch_code=$('#srch_code').val();
	var srch_name=$('#srch_name').val();
	
	//var sitename=document.getElementById('sitename').value;
	//var qutationdate=document.getElementById('qutationdate').value;
	//var client=document.getElementById('client').value;

	 
	
	//alert("Main category = "+maincat+" subcat = "+subcat+" Search Code = "+srch_code+" Search Name = "+srch_name);

	 
		$.post('directTelephonicItems_direct_ajax.php',{'main':maincat,'sub':subcat,'code':srch_code,'srch_name':srch_name,'itemlist':str,'site':sitename,'qutationdate':qutationdate,'client':client},function(data){
			$('#ItemListDiv').html(data);
		});
		
	 

}	


</script>
<?php
function string_sanitize($s) {
    $result = preg_replace("/[^a-zA-Z0-9]+/", "", html_entity_decode($s, ENT_QUOTES));
    return $result;
} 


?>
