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.

8 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
  7. Hello,

    I would like to thank you firstly for sharing smart way of creating the subpanel in sugar crm-
    http://urdhva-tech.blogspot.it/2013/02/add-custom-subpanel-in-accounts-module.html

    I followed each of your steps carefully. Basically I want to create another subpanel under accounts that will display prior employees. I followed each and every step of you as follows-

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

    49,
    'module' => 'Contacts',
    'subpanel_name' => 'ForAccounts',
    'get_subpanel_data' => 'function:get_prior_employees',
    'generate_select' => true,
    'title_key' => 'LBL_PRIOR_EMPLOYEES',
    'top_buttons' => array(),
    'function_parameters' => array(
    'import_function_file' => 'custom/modules/Accounts/customPriEmpSubpanel.php',
    //'sales_stage' => 'Prior Employees',
    'account_id' => $this->_focus->id,
    'return_as_array' => 'true'
    ),
    );

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

    .php and write the following custom label into it.age = $args[0]['sales_stage'];
    $accountId = $args[0]['account_id'];
    $return_array['select'] = " SELECT contacts.*";
    $return_array['from'] = " FROM contacts ";
    $return_array['where']='';
    $return_array['join']= "INNER JOIN contacts_cstm ON (contacts.id=contacts_cstm.id_c AND (contacts_cstm.account_id_c= '" . $accountId . "'OR account_id1_c='" . $accountId . "'))";
    return $return_array;
    }

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

    However I get the error- "Database error. Please refer to sugarcrm.log for details" after clicking on a particular account for detail. I ran my SQL query on localhost and it gave me result without any error.

    I am stuck here for a while. I would really appreciate your help.

    ReplyDelete
    Replies
    1. Please post the query from sugarcrm.log here.

      Delete

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