how to update existing opportunity record using getBeans in Suitecrm.

Hi,

I want to update my Opportunity stage when my custom button clicked.
For that I created one custom button in Opportunity editview.
and created one controller.php file in /custom/modules/opportunity/
In that file controller.php i added some code.
controller.php


<?php
class OpportunitiesController extends SugarController {
    //Can now put actions here
    public function action_stagechange(){
                     $bean = BeanFactory::getBean('Opportunities');
                      if($bean->stage_c==""){
		            	$bean->stage_c="Lead";
	             	}
	                	elseif($bean->stage_c=="Lead"){
		 	     $bean->stage_c="New Business Opportunity";
		     }
		          elseif($bean->stage_c=="New Business Opportunity"){
			       $bean->stage_c="Device Considered";
		      }
		   elseif($bean->stage_c=="Device Considered"){
			if($bean->sample_requested_date_c==""){
			echo "Sample Request Date";
			
			}
			else{
				$bean->stage_c="Sample Requested";
			}
		}
		elseif($bean->stage_c=="Sample Requested"){
			$bean->stage_c="Sample Submitted";
		}
		elseif($bean->stage_c=="Sample Submitted"){
			$bean->stage_c="Design In";
		}
		elseif($bean->stage_c=="Design In"){
			$bean->stage_c="Design Win";
		}
		
	   $bean->save();
	die();
	
    }
}

ajax code:


<script>
	function phpload(){
$.ajax({
  url: "index.php?module=Opportunities&action=stagechange",
})
  .done(function( result ) {
    alert(result);
  });
	}
	
</script>

My Button code:

<input id="stagechange" class="button primary" type="submit" name="button" value="NextStep" onclick="phpload();" title="Save">

When I click my button controller creating new opportunity it is not updating existing record.
then I gave second parameter in the getBeans.

   $bean = BeanFactory::getBean('Opportunities',$_POST['record']);

Then also it’s not working it’s creating new opportunity .

please tell me how to update my existing record when button clicked…?