AnsweredAssumed Answered

Non accessible quotes getting loaded by bean

Question asked by Sagar Honrao on Feb 13, 2019

I want to load quotes by user role access and permission.Using SugarQuery and Bean object ,I am trying to load the quotes but I am getting non-accessible quotes in the result. Please suggest me any way to get user accessible Quotes only.Here in my case, user has meeting's account access but account's quotes dose not have user access. 

The following approach I have used.

$meeting_bean = BeanFactory::getBean("Meetings",$meeting_id);

$acc_bean = BeanFactory::getBean('Accounts', $meeting_bean->parent_id);

 

if($acc_bean->load_relationship('quotes')){

//using sugarQuery

   $get_quotes = new SugarQuery();
   $get_quotes->from(BeanFactory::newBean('Quotes'), array('alias' => 'q'));
   $get_quotes->joinTable('quotes_cstm', array('alias' => 'qc'))->on()->equalsField('q.id', 'qc.id_c');
   $get_quotes->joinTable('quotes_accounts', array('alias' => 'qa'))->on()->equalsField('q.id', 'qa.quote_id')->equals('qa.deleted', 0);
   $get_quotes->select(array('q.id','q.quote_stage','qc.quote_or_order_number_c','qc.order_date_c','q.team_set_id'));
   $get_quotes->where()->equals('qa.account_id', $acc_bean->id);
   $get_quotes->where()->equals('q.deleted', 0);
   $get_quotes->where()->equals('q.quote_type',$quote_type);
   $get_quotes->where()->equals('qa.account_role', "Bill To");
   $get_quotes->limit(10);
   $quote_order = $get_quotes->execute();

 

   }

}

//using Bean object

$q = $acc_bean->quotes->get();

foreach($q as $key=>$val){
   $bean = BeanFactory::getBean('Quotes',$val);
   $c[] = $bean ->name;
}

Outcomes