Hi Daniel
A simple suggestion for accomplishing your requirement is to create a custom controller for Leads module (custom/modules/Leads/controller.php).
Inside this custom controller you implement the function action_listview, inside that function you can override the $this->bean as an instance of a new class which extends the default Lead class.
Inside that new class you implement the function create_new_list_query which is defined into SugarBean.
This function generate the $ret_array array which contains all parts for composing the sql query for the ListView.
You can modify the $ret_array['where'] to restrict the sql query for displaying only not converted Leads.
Take a look at these two piece of code:
custom/modules/Opportunities/controller.php
PHP Code:
<?PHP
require_once('include/MVC/Controller/SugarController.php');
require_once('modules/Opportunities/OpportunityInListView.php');
class OpportunitiesController extends SugarController {
function action_listview(){
$this->view_object_map['bean'] = $this->bean;
$this->view = 'list';
$GLOBALS['view'] = $this->view;
$this->bean = new OpportunityInListView();
}
}
?>
custom/modules/Opportunities/OpportunityInListView.php
PHP Code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class OpportunityInListView extends Opportunity {
function OpportunityInListView() {
parent::Opportunity();
}
function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean, $singleSelect = false){
$ret_array = parent::create_new_list_query($order_by, $where,$filter,$params, $show_deleted,$join_type, $return_array,$parentbean, $singleSelect);
$ret_array['select'] .= ", accounts.name account_name, jtl0.account_id account_id, jtl1.name agency_name, jtl2.name advertiser_name ";
$ret_array['from'] .= "
LEFT JOIN accounts_opportunities jtl0 ON opportunities.id=jtl0.opportunity_id AND jtl0.deleted=0
LEFT JOIN accounts accounts ON accounts.id=jtl0.account_id AND accounts.deleted=0 AND accounts.deleted=0
LEFT JOIN accounts jtl1 ON opportunities.agency_id=jtl1.id AND jtl1.deleted=0
LEFT JOIN accounts jtl2 ON opportunities.advertiser_id=jtl2.id AND jtl2.deleted=0";
$ret_array['where'] = str_replace("opportunities.agency_name", "jtl1.name", $ret_array['where']);
$ret_array['where'] = str_replace("opportunities.advertiser_name", "jtl2.name", $ret_array['where']);
return $ret_array;
}
}
?>
Cheers
Bookmarks