I was able to add new subpanels that handles only a specific type of opportunities by following this link.
My problem is after creating, when I try to sort it. It shows No Result afterwards and needs to be refreshed.
This is my code.
root/custom/modules/Accounts/customOpportunitiesSubpanel.php
<?php
function get_opportunities_type($params) {
$args = func_get_args();
$servicetype_c = $args[0]['servicetype_c'];
$accountId = $args[0]['account_id'];
$return_array['select'] = " SELECT opportunities.*, opportunities_cstm.*, account.id AS accounts_opportunities";
$return_array['from'] = " FROM opportunities, opportunities_cstm ";
$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['where'] = " WHERE opportunities_cstm.id_c=opportunities.id AND opportunities_cstm.servicetype_c='{$servicetype_c}'";
$return_array['join_tables'] = '';
return $return_array;
}
root/custom/modules/Accounts/customOpportunitiesSubpanel.php
<?php
$layout_defs['Accounts']['subpanel_setup']['publishing'] =
array('order' => 49,
'module' => 'Opportunities',
'subpanel_name' => 'Account_subpanel_opportunities',
'get_subpanel_data' => 'function:get_opportunities_type',
'generate_select' => true,
'title_key' => 'LBL_OPPORTUNITIES_PUBLISHING',
'top_buttons' => array(),
'function_parameters' => array(
'import_function_file' => 'custom/modules/Accounts/customOpportunitiesSubpanel.php',
'servicetype_c' => 'Publishing',
'account_id' => $this->_focus->id,
'return_as_array' => 'true'
),
'id' => 'publishing_opportunities_panel',
);
$layout_defs['Accounts']['subpanel_setup']['marketing'] =
array('order' => 50,
'module' => 'Opportunities',
'subpanel_name' => 'Account_subpanel_opportunities',
'get_subpanel_data' => 'function:get_opportunities_type',
'generate_select' => true,
'title_key' => 'LBL_OPPORTUNITIES_MARKETING',
'top_buttons' => array(),
'function_parameters' => array(
'import_function_file' => 'custom/modules/Accounts/customOpportunitiesSubpanel.php',
'servicetype_c' => 'Marketing',
'account_id' => $this->_focus->id,
'return_as_array' => 'true'
),
'id' => 'marketing_opportunities_panel',
);
$layout_defs['Accounts']['subpanel_setup']['addon'] =
array('order' => 50,
'module' => 'Opportunities',
'subpanel_name' => 'Account_subpanel_opportunities',
'get_subpanel_data' => 'function:get_opportunities_type',
'generate_select' => true,
'title_key' => 'LBL_OPPORTUNITIES_ADDON',
'top_buttons' => array(),
'function_parameters' => array(
'import_function_file' => 'custom/modules/Accounts/customOpportunitiesSubpanel.php',
'servicetype_c' => 'Addon',
'account_id' => $this->_focus->id,
'return_as_array' => 'true'
),
'id' => 'addon_opportunities_panel',
);
?>
I only copied the original opportunities subpanelās columns from this:
root/custom/modules/Opportunities/metadata/subpanels
<?php
// created: 2021-09-01 15:57:21
$subpanel_layout['list_fields'] = array (
'rmproject_code_c' =>
array (
'type' => 'autoincrement',
'default' => true,
'vname' => 'LBL_RMPROJECT_CODE',
'width' => '10%',
),
'account_name' =>
array (
'type' => 'relate',
'link' => true,
'vname' => 'LBL_ACCOUNT_NAME',
'id' => 'ACCOUNT_ID',
'width' => '10%',
'default' => true,
'widget_class' => 'SubPanelDetailViewLink',
'target_module' => 'Accounts',
'target_record_key' => 'account_id',
),
'opp_name_c' =>
array (
'type' => 'enum',
'default' => true,
'studio' => 'visible',
'vname' => 'LBL_OPP_NAME',
'width' => '10%',
),
'booktitle_c' =>
array (
'type' => 'varchar',
'default' => true,
'vname' => 'LBL_BOOKTITLE',
'width' => '10%',
),
'name' =>
array (
'name' => 'name',
'vname' => 'LBL_LIST_OPPORTUNITY_NAME',
'widget_class' => 'SubPanelDetailViewLink',
'width' => '40%',
'default' => true,
),
'sales_stage' =>
array (
'name' => 'sales_stage',
'vname' => 'LBL_LIST_SALES_STAGE',
'width' => '15%',
'default' => true,
),
'project_status_c' =>
array (
'type' => 'enum',
'default' => true,
'studio' => 'visible',
'vname' => 'LBL_PROJECT_STATUS',
'width' => '10%',
),
'date_closed' =>
array (
'name' => 'date_closed',
'vname' => 'LBL_LIST_DATE_CLOSED',
'width' => '15%',
'default' => true,
),
'amount_usdollar' =>
array (
'vname' => 'LBL_LIST_AMOUNT_USDOLLAR',
'width' => '15%',
'default' => true,
),
'invoiceno_c' =>
array (
'type' => 'varchar',
'default' => true,
'vname' => 'LBL_INVOICENO',
'width' => '10%',
),
'fulfillment_prio_level_c' =>
array (
'type' => 'enum',
'default' => true,
'studio' => 'visible',
'vname' => 'LBL_FULFILLMENT_PRIO_LEVEL',
'width' => '10%',
),
'assigned_user_name' =>
array (
'name' => 'assigned_user_name',
'vname' => 'LBL_LIST_ASSIGNED_TO_NAME',
'widget_class' => 'SubPanelDetailViewLink',
'target_record_key' => 'assigned_user_id',
'target_module' => 'Employees',
'width' => '10%',
'default' => true,
),
'aro_assigned_c' =>
array (
'type' => 'relate',
'default' => true,
'studio' => 'visible',
'vname' => 'LBL_ARO_ASSIGNED',
'id' => 'USER_ID1_C',
'link' => true,
'width' => '10%',
'widget_class' => 'SubPanelDetailViewLink',
'target_module' => 'Users',
'target_record_key' => 'user_id1_c',
),
'payment_status_c' =>
array (
'type' => 'enum',
'default' => true,
'studio' => 'visible',
'vname' => 'LBL_PAYMENT_STATUS',
'width' => '10%',
),
'date_modified' =>
array (
'type' => 'datetime',
'vname' => 'LBL_DATE_MODIFIED',
'width' => '10%',
'default' => true,
),
'edit_button' =>
array (
'vname' => 'LBL_EDIT_BUTTON',
'widget_class' => 'SubPanelEditButton',
'module' => 'Opportunities',
'width' => '4%',
'default' => true,
),
'currency_id' =>
array (
'usage' => 'query_only',
),
);
What seems to be the problem here?
Thanks