Tuesday, 5 February 2013

Add custom subpanel in Accounts module.

There comes the time when sales rep finds it irritating to view opportunities Closed Won and Closed Lost under same subpanel.

Lets make custom subpanels separating Closed Won and Closed Lost.

In this blog post, we will add those subpanels under Accounts module.

Step 1 : Create custom/Extension/modules/Accounts/Ext/Layoutdefs/<any_name>.php and write the following code into it.

<?php 
$layout_defs['Accounts']['subpanel_setup']['opp_closed_lost'] =
        array('order' => 49,
            'module' => 'Opportunities',
            'subpanel_name' => 'ForAccounts',
            'get_subpanel_data' => 'function:get_closed_lost_closed_won_opportunities',
            'generate_select' => true,
            'title_key' => 'LBL_OPPORTUNITIES_WITH_CLOSED_LOST',
            'top_buttons' => array(),
            'function_parameters' => array(
                'import_function_file' => 'custom/modules/Accounts/customOpportunitiesSubpanel.php',
                'sales_stage' => 'Closed Lost',
                'account_id' => $this->_focus->id,
                'return_as_array' => 'true'
            ),
);
$layout_defs['Accounts']['subpanel_setup']['opp_closed_won'] =
        array('order' => 50,
            'module' => 'Opportunities',
            'subpanel_name' => 'ForAccounts',
            'get_subpanel_data' => 'function:get_closed_lost_closed_won_opportunities',
            'generate_select' => true,
            'title_key' => 'LBL_OPPORTUNITIES_WITH_CLOSED_WON',
            'top_buttons' => array(),
            'function_parameters' => array(
                'import_function_file' => 'custom/modules/Accounts/customOpportunitiesSubpanel.php',
                'sales_stage' => 'Closed Won',
                'account_id' => $this->_focus->id,
                'return_as_array' => 'true'
            ),
);

Step 2 : Create custom/modules/Accounts/customOpportunitiesSubpanel.php and write following code into it.

<?php 
function get_closed_lost_closed_won_opportunities($params) {
    $args = func_get_args();
    $opportunitiesSalesStage = $args[0]['sales_stage'];
    $accountId = $args[0]['account_id'];
    $return_array['select'] = " SELECT opportunities.*";
    $return_array['from'] = " FROM opportunities ";
    $return_array['where'] = " WHERE opportunities.deleted = '0' AND opportunities.sales_stage = '" . $opportunitiesSalesStage . "'";
    $return_array['join'] = " INNER JOIN accounts_opportunities ON accounts_opportunities.opportunity_id = opportunities.id AND accounts_opportunities.deleted = '0' INNER JOIN accounts ON accounts.id = accounts_opportunities.account_id AND accounts.deleted = '0' AND accounts.id = '" . $accountId . "'";
    $return_array['join_tables'] = '';
    return $return_array;
}

Step 3 : Create custom/Extension/modules/Accounts/Ext/Language/en_us.<any_name>.php and write the following custom label into it.

<?php 
$mod_strings['LBL_OPPORTUNITIES_WITH_CLOSED_LOST'] = "Opportunities With Closed Lost";
$mod_strings['LBL_OPPORTUNITIES_WITH_CLOSED_WON'] = "Opportunities With Closed Won";

Step 4 : Do Quick Repair and Rebuild from Admin panel.



Feel free to leave comments.

6 comments:

  1. Goshh i love this one it is very helpful thanks so much

    ReplyDelete
  2. Thank you for your appreciation!

    ReplyDelete
  3. Thank you very much, nice solution. And may be do You know, how to add field from related table to displayed fields? If I try:
    $return_array['select'] = " SELECT opportunities.*, something_related ";
    it doesn't work.

    ReplyDelete
  4. Janusz, did you link related module to the query by join?

    ReplyDelete
  5. very helpful tip. thanks a lot

    ReplyDelete
  6. I don't know which version of sugarcrm you're talking about. I'm using SugarCRM CE 6.4.2 and I did the exact you mentioned here but the situation I faced is like a blank subpanel. To get data I needed to create one file named ForAccounts.php in custom/modules/opportunities/metadata/subpanels and I defined the subpanel layout there and it worked. Anyway Nice tricky way to get custom subpanel. very helpful indeed :)

    ReplyDelete

Urdhva Tech Pvt. Ltd. Powered by Blogger.

Urdhva Tech

My Photo
SugarCRM Consultants Contact us at contact@urdhva-tech.com Skype : urdhvatech

Search This Blog

Loading...

Stay connected Socially

     

Total Pageviews

Popular Posts