Subpanels Cases

Let me try giving you a copy of a different example. My advice is to first try to get my example working as it is, without changing anything; only after it’s working you try and adapt it to your requirement, ok?

Create this file
custom/Extension/modules/Accounts/Ext/Layoutdefs/Leads.php

with these contents:

<?php

$layout_defs["Accounts"]["subpanel_setup"]['leads'] = array(
    'order' => 80,
    'module' => 'Leads',
    'sort_order' => 'asc',
    'sort_by' => 'first_name, last_name',
    'subpanel_name' => 'default',
    'get_subpanel_data' => 'function:getRelatedLeadsQueryData',
    'function_parameters' => array(
    'import_function_file' => 'custom/modules/Accounts/GetLeadsSubpanelData.php',
    'link' => 'leads'
    ),
    'add_subpanel_data' => 'lead_id',
    'title_key' => 'LBL_LEADS_SUBPANEL_TITLE',
    'top_buttons' => array(
        array('widget_class' => 'SubPanelTopCreateLeadNameButton'),
        array('widget_class' => 'SubPanelTopSelectButton',
            'popup_module' => 'Opportunities',
            'mode' => 'MultiSelect',
        ),
    ),
);

Now let’s create that file that provides the query:
custom/modules/Accounts/GetLeadsSubpanelData.php

<?php
require_once 'custom/modules/Accounts/BuildLeadsSubpanelQueryService.php';

function getRelatedLeadsQueryData($param){
    $service = new BuildLeadsSubpanelQueryService();
    return $service->buildQuery($param);
}

And now let’s create that class in file
custom/modules/Accounts/BuildLeadsSubpanelQueryService.php

<?php

class BuildLeadsSubpanelQueryService
{

    public function __construct()
    {}

    public function buildQuery($param)
    {
        global $app;
        $controller = $app->controller;
        $bean = $controller->bean;
        $query = "
            SELECT *
            FROM leads
            WHERE leads.account_id = '$bean->id'
              AND leads.status not in ('converted')
              AND leads.deleted = 0
               ";
        return $query;
    }
}

I am using the already-existing label LBL_LEADS_SUBPANEL_TITLE, but for your case you will want to create a new, custom label, check the Developer Guide, Language chapter.

Now you should see a subpanel under Accounts that shows you Leads, but excluding ā€œconvertedā€ leads.

You can adapt this to your requirement, it allows you to use any SQL to get the data you want. Good luck.