|
|
|
@ -54,18 +54,20 @@ sub TO_JSON {
|
|
|
|
|
|
|
|
|
|
__PACKAGE__->result_source_instance->is_virtual(1);
|
|
|
|
|
|
|
|
|
|
__PACKAGE__->result_source_instance->view_definition("
|
|
|
|
|
select bm.contract_id,max(bm.id) as actual_bm_id from billing.billing_mappings bm
|
|
|
|
|
inner join
|
|
|
|
|
(select bmm.contract_id, max(bmm.start_date) max_start_date
|
|
|
|
|
from billing.billing_mappings bmm
|
|
|
|
|
where ( bmm.`end_date` >= ? OR bmm.`end_date` IS NULL )
|
|
|
|
|
AND ( bmm.`start_date` <= ? OR bmm.`start_date` IS NULL )
|
|
|
|
|
AND ( ? is null OR bmm.`contract_id` = ? )
|
|
|
|
|
group by bmm.contract_id
|
|
|
|
|
) bmm on bm.contract_id=bmm.contract_id and (bm.start_date=bmm.max_start_date or (bmm.max_start_date is null and bm.start_date is null))
|
|
|
|
|
group by bm.contract_id
|
|
|
|
|
");
|
|
|
|
|
__PACKAGE__->result_source_instance->view_definition(<<SQL);
|
|
|
|
|
SELECT bm.contract_id,max(bm.id) AS actual_bm_id FROM billing.billing_mappings bm
|
|
|
|
|
INNER JOIN (
|
|
|
|
|
SELECT bmm.contract_id, MAX(bmm.start_date) max_start_date
|
|
|
|
|
FROM billing.billing_mappings bmm
|
|
|
|
|
WHERE ( bmm.`end_date` >= ? OR bmm.`end_date` IS NULL )
|
|
|
|
|
AND ( bmm.`start_date` <= ? OR bmm.`start_date` IS NULL )
|
|
|
|
|
AND ( ? IS NULL OR bmm.`contract_id` = ? )
|
|
|
|
|
GROUP BY bmm.contract_id
|
|
|
|
|
) bmm ON bm.contract_id=bmm.contract_id
|
|
|
|
|
AND (bm.start_date=bmm.max_start_date
|
|
|
|
|
OR (bmm.max_start_date IS NULL AND bm.start_date is null))
|
|
|
|
|
GROUP BY bm.contract_id
|
|
|
|
|
SQL
|
|
|
|
|
|
|
|
|
|
#__PACKAGE__->result_source_instance->view_definition("select bma.contract_id, bma.id as actual_bm_id
|
|
|
|
|
#from billing.billing_mappings bma
|
|
|
|
|