All pastes #747146 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-23 20:03 UTC
rendered paste body
/**
 * GenerateOpportunityForNewQuote
 *
 *			$hook_array['after_save'][] = Array (1, 'Quotes_GenerateOpportunityForNewQuote', 'custom/modules/OmniHooks/OmniHooks.php', 'OmniHooks', 'GenerateOpportunityForNewQuote'); 
 *
 *
 * @param	SugarBean	$bean				: $this bean passed in by reference
 * @param	string			$event				: the current event (i.e. before_save)
 * @param	array			$arguments 	: array of arguments that are specific to the event
 * @return  nothing
 */
function GenerateOpportunityForNewQuote(&$bean, $event, $arguments)
{
	/// Quote has not been saved;  nothing to do.
	if($bean->quote_num == 0) return;
	
	/// Get any existing opportunities
	$bean->set_opportunity();
	
	/// Opportunity has already been created;  nothing to do.
	if($bean->opportunity_id != 0  ||  strlen($bean->opportunity_id) == 0) return;
	
	/// Opportunity has already been created;  nothing to do.
	if(strlen($bean->name) == 0) return;
	
	$GLOBALS['log']->info("GenerateOpportunityForNewQuote Called; $bean->name ($bean->id)");
			
	require_once('modules/Opportunities/Opportunity.php');
	
	$opp = new Opportunity();
	$opp->assigned_user_id = $bean->assigned_user_id;
	$opp->date_closed = $bean->date_quote_closed;
	// or
	//$opp->date_closed = $bean->date_quote_expected_closed;
	
	$opp->name = $bean->name;
	$opp->lead_source = 'Self Generated';
	$opp->sales_stage = 'Proposal/Price Quote';
	$opp->opportunity_type = 'New Business';
	
	$opp->team_id = $bean->team_id;
	
	if(empty($bean->total))
		$amount = "0.00";
	else
		$amount=unformat_number ($bean->total);
	
	$opp->amount = $amount;
	$opp->quote_id = $bean->id;
	$opp->currency_id = $bean->currency_id;
	$opp->account_id = $bean->billing_account_id;
	$opp->description = $bean->description;
	$opp_id = $opp->save();
			
	
	//$bean->opportunity_id = $opp_id;
	//$bean->opportunity_name = $opp->name;
	
//		$GLOBALS['log']->info("bean->load_relationship('opportunities')");
//		$bean->load_relationship("opportunities");
//		$list = $bean->opportunities->get();
//		
//		$GLOBALS['log']->info("bean->opportunities->get()");
//		$GLOBALS['log']->info($list);
//		
//		$bean->opportunities->add($opp_id);
	
	//$bean->set_opportunity();
	//$bean->save();
	
	
	$GLOBALS['log']->info("done!");
}