<?php
session_name('CAKEPHP'); session_start();
error_reporting(0); 

//$first_date=date('24/10/2015');
$first_date=date('d/m/Y',strtotime($_SESSION['financialYrStart']));
$cur_date=date('31/m/Y');

//echo $_REQUEST['from_date'];
?>
<script type="text/javascript">
function checkval(){
	var idsite = document.getElementById("site").value;
	var idstore = document.getElementById("store1").value;
	var fromdate = document.getElementById("from_date").value;
	var todate = document.getElementById("to_date").value;
	var maincat = document.getElementById("maincat").value;
	if(idsite=='0'){
		alert("Select Site Name First.");
		return false;
	}
	
	else if(fromdate=='')
	{
		alert("Select From date.");
		return false;
	}
		else if(todate=='')
	{
		alert("Select To date.");
		return false;
	}
	
	else if(maincat=='0' && idstore=='0')
	{
	alert("Select Main category First.");
		return false;
	}
	return true;
}
</script>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Stock Summary</h1>
<form method="post" action="">

<table width="100%" border="0" cellspacing="0" cellpadding="3">
	<tr class="row1">
    	<td width="13%" align="right">Site <span style="color:#FF0000">*</span></td>
        <td width="20%"><?php
		 $ss1="Select loccode, locationname from locations  where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	  	 $site_sql1=DB_query($ss1,$db);	 
	?>
			<select name="site" id="site" onchange="showsitename160(this.value)">
                <option value="">All</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">Store <span style="color:#FF0000">*</span></td>
        <td width="20%">
			<div id="storedata7">
            	<select name="store1" id="store1">
				<option value='0'>All</option>
                <?php 
	 			$store_sql = "SELECT id, StoreName,storecode FROM storetype where Store_Site = '".$_REQUEST['site']."'";
	 			$store_result = DB_query($store_sql,$db);
	 			while($store_row = DB_fetch_array($store_result))
				{
					$p='';
					if($store_row['id'] == $_REQUEST['store1'])
						$p="selected";
	 			?>
                <option value="<?php echo $store_row['id'] ?>"<?php echo $p; ?>><?php echo $store_row['StoreName']?></option>
                <?php } ?>
                </select>
          	</div>
		</td>
		<td width="13%" align="right">Enter Part Name Of Item</td>
		<td><input type="text" name="itemName" value="" onkeyup="showItems(this.value)" /></td>
	</tr>
	<tr class="row1">
    <td align="right">Main Category</td>
	<td><select name="maincat" id="maincat" onchange="showsubcat(this.value)">
	<option value="0">Select</option>
                <?php 
	 			$store_sql = "SELECT * FROM stockmaincategory where CompanyId='".$_SESSION['ACGCompanyId']."'";
	 			$store_result = DB_query($store_sql,$db);
	 			while($store_row = DB_fetch_array($store_result))
				{
					$p='';
					if($store_row['id'] == $_REQUEST['maincat'])
						$p="selected";
	 			?>
                <option value="<?php echo $store_row['id'] ?>"<?php echo $p; ?>><?php echo $store_row['stockmaincategoryname']?></option>
                <?php } ?>
                </select></td>
	<td align="right">Sub Category</td>
	<td><div id="subcatdata">
	<?php 
	 $store_sql = "SELECT * FROM stockcategory  where stockmaincategory = '".$_POST['maincat']."'";
	 ?>
	<select name="subcat" id="subcat" onchange="showdata(this.value)">
	<option value="0">Select</option>
			<?php
 			$store_result = DB_query($store_sql,$db);
			while($store_row = DB_fetch_array($store_result))
			{
				;
				$p='';
				if($store_row['id'] == $_REQUEST['subcat'])
				$p="selected";
			?>			
	<option value="<?php echo $store_row['id'] ; ?>" <?php echo $p ; ?>><?php echo $store_row['categorydescription']; ?></option>
			 <?php }?>              
              </select></div>	
	</td>
    <td valign="top" rowspan="2" align="right">Select Item</td>
    <td rowspan="2"><div id="itemid">
  <div style="overflow:auto; height:100px; border:1px solid #ccc; background:#fff; padding:2px 3px;">
                  <?php 
					$item_sql=DB_query("select id,StockID,item_name from item_master where CompanyId='".$_SESSION['ACGCompanyId']."' order by StockID ASC",$db);
					$c3=0;
					while($row3=DB_fetch_array($item_sql))
					{ 
						$c='';
						if($_REQUEST['item'][$c3]==$row3['id'])
							{$c="checked";}
					?>
                  <input type="checkbox" name="item[<?php echo $c3;?>]" id="item_<?php echo $c3;?>" value="<?php echo $row3['id'];?>" <?php echo $c;?>/>
                  <?php echo $row3['StockID']." - ".$row3['item_name'];?><br />
                  <?php 		
					$c3++;
					}
					if($_REQUEST['view'] && $_REQUEST['item']){
						$itemString[]=$_REQUEST['item'];
						$a=implode(",", $_REQUEST['item']); 
					}	 
				?>
                </div>
          </div></td>
	</tr>	
	<tr class="row1">
        <td align="right">From Date</td>
        <td><input type="text" name="from_date" id="fromdate" value="<?php if($_REQUEST['from_date']!='') { echo $_REQUEST['from_date']; } else { echo $first_date;}  ?>"    class="datepicker"></td>
        <td align="right">To Date</td>
        <td><input type="text" name="to_date" id="todate" value="<?php if($_REQUEST['to_date']!='') { echo $_REQUEST['to_date']; } else { echo $cur_date; } ?>"   class="datepicker">
        	<input type="hidden" value="<?php echo ConvertSQLDate($_SESSION['financialYrStart']);?>" id='from'>
    		<input type="hidden" value="<?php echo ConvertSQLDate($_SESSION['financialYrEnd']);?>" id='to'>
        </td>
    </tr>
    <tr class="row1">
        <td align="right">Type</td>
        <td><select name="type" id="type">
			<option value="0">Select</option>	
			<option value="W">Without Zero</option>
			<option value="Z">Zero</option>			
          </select>
        </td>
        <td colspan="4"></td>
    </tr>
    <tr class="row1">
    	<td colspan="6" style="text-align:center">
          <input type="submit" name="view" value="View" class="search" onclick="return checkval()">
        </td>
    </tr>
</table>
	  
</form>


 <?php
     if(isset($_POST['view']))
       {

//$_SESSION['stock_print']=$_REQUEST;
					//echo "<pre>";
	 	           // print_r($_SESSION['stock_print']);
       	 $type=$_REQUEST['type'];
					if($_REQUEST['from_date']=='')
					{
						$_REQUEST['from_date']=$_SESSION['financialYrStart'];
						$from_date=$_REQUEST['from_date'];
						$from=$from_date;
					}else{
						 $from_date=$_REQUEST['from_date'];
						$from_date_brk=explode('/',$from_date);
						 $from=$from_date_brk[2]."-".$from_date_brk[1]."-".$from_date_brk[0];
					}
					if($_REQUEST['to_date']=='')
					{
						$_REQUEST['to_date']=$_SESSION['financialYrEnd'];
						$to_date=$_REQUEST['to_date'];
						$to=$to_date;
					}else{
						$to_date=$_REQUEST['to_date'];
						$to_date_brk=explode('/',$to_date);
						$to=$to_date_brk[2]."-".$to_date_brk[1]."-".$to_date_brk[0];	
					}					

		/*	if($_REQUEST['type']!='0')
						{
			$type=$_REQUEST['type'];
			if($type=='00')
			{

			}
		$filter5[]="stock_valuation_tbl.trasaction BETWEEN '".$from."' and '".$to."'";
						}
					*/
		if($filter5!='')
	{
		$filter6=implode(' and ',$filter5); 		
	}
					$_SESSION['stock_print']=$_REQUEST;
					//echo "<pre>";
	 	           // print_r($_SESSION['stock_print']);
					if($_REQUEST['from_date']=='')
					{
						$_REQUEST['from_date']=$_SESSION['financialYrStart'];
						$from_date=$_REQUEST['from_date'];
						$from=$from_date;
					}else{
						 $from_date=$_REQUEST['from_date'];
						$from_date_brk=explode('/',$from_date);
						 $from=$from_date_brk[2]."-".$from_date_brk[1]."-".$from_date_brk[0];
					}
					if($_REQUEST['to_date']=='')
					{
						$_REQUEST['to_date']=$_SESSION['financialYrEnd'];
						$to_date=$_REQUEST['to_date'];
						$to=$to_date;
					}else{
						$to_date=$_REQUEST['to_date'];
						$to_date_brk=explode('/',$to_date);
						$to=$to_date_brk[2]."-".$to_date_brk[1]."-".$to_date_brk[0];	
					}
									
				    if($_REQUEST['site']!='0')
				    {
					 $site=$_REQUEST['site'];
					}
					
					if($_REQUEST['store1']==0)
					{
					 $store12=array();
					 $store_sql = "SELECT id FROM storetype where Store_Site = '".$_REQUEST['site']."'";
					 $store_sql1=DB_query($store_sql,$db);
					 while($st_rows=DB_fetch_array($store_sql1))
					 {
					 $store12[]=$st_rows['id'];
					 }
					 $store=implode("','",$store12);
					 }
					else
					$store=$_REQUEST['store1'];
					if($_REQUEST['maincat']!='0')
					$filter2[]="CategoryID='".$_REQUEST['maincat']."'";
					if($_REQUEST['subcat']!='0')
					$filter2[]="SubCategoryID='".$_REQUEST['subcat']."'";
					
					 $item=$_REQUEST['item'];	
					 //print_r($item);				
					if($item!=''){
					$item_string=implode("','",$item);
					$filter2[]="id in('".$item_string."')";					
					 }
					 if($filter2!='')
					 {					
					 $filter4=implode(' and ',$filter2);
					 }
					 $function_filter[0]=$site;					 
					$function_filter[1]=$store;	
					$function_filter[2]=$from;
					$function_filter[3]=$to;
					$fdate=$from;
 //date($from);
 //date($to);
if($_REQUEST['from_date']!='' && $_REQUEST['to_date']!='')
						{
		$filter5[]="trasaction BETWEEN '".date($from)."' and '".date($to)."'";
		$filter_pre[]="trasaction <'".date($from)."'";
						}
if($_REQUEST['site']!='')
						{
		$filter5[]="site = '".$_REQUEST['site']."'";
		$filter_pre[]="site = '".$_REQUEST['site']."'";
						}
if($_REQUEST['store1']!='' && $_REQUEST['store1']!='0')
						{
		$filter5[]="store = '".$_REQUEST['store1']."'";
		$filter_pre[]="store = '".$_REQUEST['store1']."'";
						}
 if($filter5!='')
	{
		$filter6=implode(' and ',$filter5); 		
	}	

	if($filter_pre!='')
	{
		$filter_pre1=implode(' and ',$filter_pre);
	}
	
?>

 <?php
  if($branch!='')
  {
   	$branch=$s->getField('locations','loccode',$_REQUEST['site'],'locationname');
  }
  else
  {
  	$branch="All";
  }

 if($_REQUEST['store1']!='0')
  $storedata="store  ".$s->getField('storetype','id',$_REQUEST['store1'],'StoreName');
  else
  $storedata="ALL Store";
  if($_REQUEST['maincat']!='0' && $_REQUEST['store1']!=='0')
  {
  $sub=$s->getField('stockcategory','id',$_REQUEST['subcat'],'categorydescription');
  $cat=$s->getField('stockmaincategory','id',$_REQUEST['maincat'],'stockmaincategoryname');
  }
  if($_REQUEST['maincat']!='0')
  {
  $message="Showing Records of  ".$storedata." of Branch -- ".$branch."   
  Category -- ".$cat." -- and  SubCategory -- ".$sub." and 
  From  ".$_REQUEST['from_date']." to ".$_REQUEST['to_date']."";
  }
  elseif($from_date!="" && $to_date!="")
  {
   $message="Showing Records of   ".$storedata."  of Branch --  ".$branch."   
   From   ".$_REQUEST['from_date']." to ".$_REQUEST['to_date']."";
  }
  elseif($from_date=="" && $to_date=="")
  {
   $message="Showing Records of   ".$storedata."  of Branch --  ".$branch."   
   From   ".ConvertSQLDate($_SESSION['financialYrStart'])." to ".ConvertSQLDate($_SESSION['financialYrEnd'])."";
  }
 ?>
    <?php //for($k=0; $k<5; $k++){
   
   if($item!=''){
			$item_string=implode("','",$item);
			$filter2[]="id in('".$item_string."')";
		}   
   
   $item2=$_REQUEST['item'];
	if($item2!=''){
		 $item_string1=implode(",",$item2);
}
 ?> 

<?php  if($_REQUEST['view']!=''){?>
<p align="center"><strong><?php echo $message; ?></strong> <a href="batch_wise_stock.php" target="_blank" style="float:right;"><input type="button" name="print" class="search" value="Print" ></a></p>
<?php } ?>
  
	<table width="100%" border="0" cellspacing="0" cellpadding="3" class="thborder">
  <tr>
	  <th width="5%">S. No.</th>
	  <th>Batch</th>
	  <th width="9%">Date of Mfg.</th>
	  <th width="9%">Date of Expiry</th>
	  <th width="9%">Unit</th>   
	  <th width="9%">Opening Quantity</th>
	  <th width="9%">Received Quantity</th>
	  <th width="9%">Issue Quantity</th>  
	  <th width="9%">Closing Balance</th>
</tr>
  <?php 
		$subQuery='';       
	    if($item_string1!='')
	     $subQuery.=" and id IN(".$item_string1.")";

	     if($_REQUEST['maincat']!=0)
	     	 $subQuery.=" and CategoryID='".$_REQUEST['maincat']."'";
	     if($_REQUEST['subcat']!=0)
	     	 $subQuery.=" and SubCategoryID='".$_REQUEST['subcat']."'";
		 	 $_SESSION['subQuery']=$subQuery; 
		 	 $_SESSION['filter6']=$filter6;
		     $sql1="select * from item_master where 1=1 ".$subQuery." order by CategoryID,SubCategoryID,item_name ASC ";
			 $_SESSION['sql1']=$sql1;
		     $_SESSION['sqlquery_'.$rd]=$sql1;	  
		     $_SESSION['from_date']=$_REQUEST['from_date'];
		     $_SESSION['to_date']=$_REQUEST['to_date'];
		     $_SESSION['store']=$_REQUEST['store1'];
 //echo  $sql1="select * from item_master where  ".$filter4."   ";

//echo  $sql1="select * from item_master where  ".$filter4." ";
     $result1=DB_query($sql1,$db);
    
  while($row1=DB_fetch_array($result1))
  {    
        // array($row1['id']=>'item_id');
         $sql2="select * from stock_valuation_tbl  where mst_itemid= ".$row1['id']." and ".$filter6."";
 					// $_SESSION['sql2']= $sql2;

     				 $result2=DB_query($sql2,$db);
     				 if(DB_num_rows($result2)>0)
     				 {
     				 	 $itemarray[]=$row1['id'];

     				 	while($row2=DB_fetch_array($result2))
 						 {
                              $optype='';$Receivedqty='';$issueqty='';$closing='';
                              $oppreqty='';$preReceivedqty='';$preissueqty='';$preclosing='';
                        
                        $optype=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                        	and ".$filter6." and type='OP'","sum(inwardqty_primary)");
                         $Receivedqty=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                        	and ".$filter6." and type!='OP'","sum(inwardqty_primary)");
                         $issueqty=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                        	and ".$filter6." ","sum(outwardqty_primary)");
		 						 		//$type=$row2['type'];
		    							//if($row2['type']=='OP')	{	$optype=$row2['inwardqty_primary'];	}
		    							//else {		$optype= "0";		}

                         $oppretype=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                        	and ".$filter_pre1." and type='OP'","sum(inwardqty_primary)");
                         $preReceivedqty=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                        	and ".$filter_pre1." and type!='OP'","sum(inwardqty_primary)");
                         $preissueqty=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                        	and ".$filter_pre1." ","sum(outwardqty_primary)");

                             $preqty=$oppretype+$preReceivedqty-$preissueqty;
		    						
		    							$batch=$row2['batch_no'];
		    							$mid=$row2['primary_unit'];
                                          
                                       $closing=($optype+$Receivedqty)-$issueqty+$preqty;                 
                                if($batch!='')
							    $batch_item_array[$row1['id']][$batch]=array("OP"=>$optype+$preqty,"recieve"=>$Receivedqty,"issue"=>$issueqty,"unit"=>$mid,"closing"=>$closing,"mdate"=>$row2['date_of_mfg'],"edate"=>$row2['date_of_expiry']);
							    //array('op'=>$optype,'recieve'=>$Receivedqty,$issueqty=>'issue',$closing=>'closing');
							  
     				 }
     				 	}  
     				 }
     				//echo "<pre>";
     				//print_r($itemarray);
     				 //print_r($batch_item_array);

     				 	?>
     				 		
     				 	<?php foreach ($itemarray as $key => $value)   {   ?>   							
   
      <?php    
//echo "<pre>"; 
  //print_r($itemarray); 
    $t='1'; 
    $total='';
          foreach($batch_item_array[$value] as $key1=>$value1)
           {   
               if($_REQUEST['type']=='W' || $_REQUEST['type']=='0')     
               {   	
               $total=$total+$value1['closing'];			
          	?>
	          			<?php if($item1!=$value) { ?>
	          		<tr bgcolor="#e4e4e4" style="color:#00695f;">
						<td></td> 						      
						<td colspan="8"><strong> <?php echo $s->getField('item_master','id',$value,'item_name');  ?></strong></td>
					</tr>   
	     				<?php $item1=$value; } ?>			 
    				<tr>				
    					<td><?php echo $t;  ?></td>
    					<td><?php echo $key1;  ?></td>
    					<td><?php echo date('d/m/Y',strtotime($value1['mdate']));?></td>
    					<td><?php echo date('d/m/Y',strtotime($value1['edate']));?></td>
    					<td><?php echo $s->getField('unitsofmeasure','unitid',$value1['unit'],'unitname');?></td>
    					<td style="text-align:right;"><?php echo $value1['OP'];  ?></td>		    					
    					<td style="text-align:right;"><?php echo $value1['recieve'];  ?></td>
    					<td style="text-align:right;"><?php echo $value1['issue'];  ?></td>  
    					<td style="text-align:right;"><?php  $c=$value1['closing']; echo number_format((float)$c, 2, '.', '');    ?></td>
    				</tr>
    
    	<?php  }
    	 else  if($_REQUEST['type']=='Z' && $value1['closing']<='0' )  { ?>
        <?php if($item1!=$value) { ?>
          		    <tr bgcolor="#e4e4e4" style="color:#00695f;">
					    <td></td> 
					    <td colspan="8"><strong> <?php echo $s->getField('item_master','id',$value,'item_name');  ?></strong></td>
     				</tr>   
     					<?php $item1=$value; } ?>	
                   	<tr>				
    					<td><?php echo $t;  ?></td>
    					<td ><?php echo $key1;  ?></td>
    					<td><?php  echo date('d/m/Y',strtotime($value1['mdate']));?></td>
    					<td><?php  echo date('d/m/Y',strtotime($value1['edate']));?></td>
    					<td><?php	echo $s->getField('unitsofmeasure','unitid',$value1['unit'],'unitname');?></td>
    					<td style="text-align:right;"><?php echo $value1['OP'];  ?></td>		    					
    					<td style="text-align:right;"><?php echo $value1['recieve'];  ?></td>
    					<td style="text-align:right;"><?php echo $value1['issue'];  ?></td>  
    					<td style="text-align:right;"><?php echo $value1['closing'];   ?></td>
    				</tr>
    	<?php  } $t++;  	}         	 ?>	
    	<?php if($total>'0') { ?>

    	<tr>
    	<td colspan="8" style="text-align:right;"><strong>Total=</strong></td>
    	<td style="text-align:right;"><strong><?php echo  number_format((float)$total, 2, '.', '');  ?></strong></td>
    	</tr>
    		<?php  } } ?>
    </table>

  <?php } ?>

</div>
</div>

<script type="text/javascript">
	function checkdate(date)
{
	var from =document.getElementById('from').value;
	var to =document.getElementById('to').value;
	
		var cdate=date.split("/");
		var sdate=from.split("/");
		var edate=to.split("/");

		cdate[1]=cdate[1]-1;
		sdate[1]=sdate[1]-1;
		edate[1]=edate[1]-1;
			 
		var dateC = new Date(cdate[2], cdate[1], cdate[0]); //Year, Month, Date 
		var dateS = new Date(sdate[2], sdate[1], sdate[0]); //Year, Month, Date
	    var dateE = new Date(edate[2], edate[1], edate[0]); //Year, Month, Date

	    if (dateS > dateE) {
	        alert("Start Date is not greather then Date End.");
	        document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	        
	    }

	    if (dateC > dateE) {
	        alert("Date Not greather than "+to);
	       document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	       
	    }

	    if (dateC < dateS) {
	        alert(" Date Not less than "+from);
	        document.getElementById('fromdate').value=from;
	        document.getElementById('todate').value=to;
	       
	    }	
	
	
}

</script>
<script type="text/javascript">
function showItems(str)
{
   $.post("Get_itemcode.php",{"partName":str},function(data){
	document.getElementById("itemid").innerHTML=data;
});
}
function showsitename160(str)
{

var xmlhttp;
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)
    {
	var data=xmlhttp.responseText.split("__");	
	document.getElementById("storedata7").innerHTML=data[0];
	  }
  }
  xmlhttp.open("GET","get_sitenamedata3.php?site="+str,true);
	xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

	
}


function showsubcat(str)
{
var xmlhttp;
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)
    {
	var data=xmlhttp.responseText.split("__");	
	document.getElementById("subcatdata").innerHTML=data[0];
	document.getElementById("itemid").innerHTML=data[1];
	  }
  }
  xmlhttp.open("GET","get_sitenamedatasubcat.php?site="+str,true);
	xmlhttp.send();




}

function showdata(str)
{
 if(str=="")
  {
  document.getElementById("itemid").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("itemid").innerHTML=xmlhttp.responseText;
    }
  }
  var cat=document.getElementById("maincat").value;
xmlhttp.open("GET","Get_itemcode1.php?partName="+str+"&main="+cat,true);
xmlhttp.send();

}


</script>



 