I just followed your example to add a panel with invoices in AOS_Products, because, in our process the sell isnt done until we send the invoice, the quote is just before the invoice.
As I´m not developer (just and enthusiast) I search for this, and didnt found a solution, so, I think is a good way to share with someone thats looking for some similar to have the other steps.
First, the PANEL.
This is done exactly where @pgr wrote:
custom/Extension/modules/Accounts/Ext/Layoutdefs/ANYNAMEYOUWANT.php
// created: 2022-12-23 00:45:08
$layout_defs["AOS_Products"]["subpanel_setup"]['aos_products_aos_invoices_1'] = array (
'order' => 100,
'module' => 'AOS_Invoices',
'sort_order' => 'asc',
'sort_by' => 'number',
'subpanel_name' => 'default',
'title_key' => 'ANY NAME YOU WANT TO USE FOR THE PANEL',
'get_subpanel_data' => 'function:getCustomersInvoicedProductsQuery',
'function_parameters' => array(
'import_function_file' => 'custom/modules/AOS_Products/GetInvoiceSubpanelData.php',
'link' => 'aos_invoices'
),
'top_buttons' =>
array (
0 =>
array (
'widget_class' => 'SubPanelTopButtonQuickCreate',
),
1 =>
array (
'widget_class' => 'SubPanelTopSelectButton',
'mode' => 'MultiSelect',
),
),
);
Second, the query. This is the same code that PGR wrote, and this have to be saved in:
custom/modules/Accounts/GetInvoiceSubpanelData.php
Note that I changed the php file name to fit better my needs.
<?php
require_once 'custom/modules/AOS_Products/BuildInvoiceSubpanelQueryService.php';
function getCustomersInvoicedProductsQuery($param){
$service = new BuildInvoiceSubpanelQueryService();
return $service->buildQuery($param);
}
Third, the class, that run the query. This was the most dificult part because I´m not a developer, I did easy and its working without much, This is saved in the same place, and I also changes the file name to fit my needs:
custom/modules/Accounts/BuildLeadsSubpanelQueryService.php
<?php
class BuildInvoiceSubpanelQueryService
{
public function __construct()
{}
public function buildQuery($param)
{
$query = "
SELECT aos_invoices.*
FROM aos_invoices
WHERE aos_invoices.deleted = 0
AND aos_invoices.status = 'Paid'
";
return $query;
}
}
In this case, I just needed the Invoice table (AOS_INVOICE) so I just query this whole with SELECT and FROM.
Not sure if that´s the better way, but seems to work.
EDIT: Thanks to PGR for pointing that maybe keep the deleted filter was a good idea. I also added another condition to filter just the STATUS as Paid.