$stock=DB_query("Select stockbalance from stock_maintenance where itemcode='".$_REQUEST['mst_itemid'][$i]."' and store='".$_REQUEST['storecode']."'",$db);
					$stock_row=DB_fetch_array($stock);
					$num=DB_num_rows($stock);					
					if($num>0)
					{						
				  if($stock_row['itemcode']=$_REQUEST['mst_itemid'][$i] and $stock_row['site']=$_REQUEST['sitecode']  and $stock_row['store']=$_REQUEST['storecode'] )
					{
					 $condition1="itemcode='".$_REQUEST['mst_itemid'][$i]."' && site='".$_REQUEST['sitecode']."' && store='".$_REQUEST['storecode']."' ";
					$current_bal=$stock_row['stockbalance']+$_REQUEST['reciveqty'][$i];
					
					$balance_arr['site'] = $_REQUEST['sitecode'];
					$balance_arr['store'] = $_REQUEST['storecode'];  
					$balance_arr['itemcode']= $_REQUEST['mst_itemid'][$i];										
					$balance_arr['stockbalance']=$current_bal;					
					$balance_arr['created_by']=$_SESSION['UserID'];	
									
				 	$update1=$s->EditRecord(stock_maintenance, $balance_arr, $condition1);
					
					$row1=DB_query($update1,$db);
					
					if(!$row1)
					{
	  					 die('Error'.DB_error());
					}
					}
					}
					else{
						
						$balance_arr['site'] = $_REQUEST['sitecode'];
						$balance_arr['store'] = $_REQUEST['storecode'];  
						$balance_arr['itemcode']= $_REQUEST['mst_itemid'][$i];						
						$balance_arr['stockbalance']= $_REQUEST['reciveqty'][$i];
						$balance_arr['created_by']=$_SESSION['UserID'];
						$insert_stock_maintenance=$s->insertRecord('stock_maintenance', $balance_arr);
						$row1=DB_query($insert_stock_maintenance,$db);
						
						if(!$row1)
						{
		  					 die('Error'.DB_error());
						}
					}