As Billing Admin I need a more detailed view comparing different billing batches to understand how it is moving on

Description

PRDE - Story default text according to the team DoR (Definition of Ready)

01 - PERSON OF CONTACT (PERSON THAT CAN ANSWER QUESTIONS ABOUT THE PROBLEM): @Robson Thanael Poffo

03 - PROBLEM (WHAT'S THE CURRENT PROBLEM SCENARIO OR PAIN TO BE RESOLVED?):

It is hard from the Billing Admin perspective to understand how billing is floating when it comes to approve a not published batch billing.

How we are solving today the problem: https://docs.google.com/spreadsheets/d/1D7vG0vfSIz1EkVY3slFE4imOdQh3fRuEB-sYXTc8otI/edit#gid=1695928722

  • Show months in a colunar way, so we can compare it.
  • Allow to group by tenant or tenant and service.
  • Allow to filter in one way (if possible, combine both filters):
    • allow to filter by billing account
    • allow to filter by carol app
  • Allow to filter by service.

05 - WHO CAN USE THIS FEATURE (USER ROLES): Billing Admin
09 - ASSETS (FIGMA LINKS, RELEVANT DOCUMENTATION LINKS, JSON EXAMPLES, ETC):

https://www.figma.com/file/FiL1iRG6RPjuNCgVzgGqvaZ3/%F0%9F%9F%A3-Carol-3.0?type=design&node-id=34021-63237&mode=design&t=MoKTdNowo2EWbrgL-4

10 - ACCEPTANCE CRITERIA:

  • Allow the Billing Admin to visualize the data in a tabular way
  • Add button “Compare batches” on Batch tab
  • Navigate to Compare batches table
  • Allow to filter by resource, tenant, period and batch

Sharing a query we are using to explore the data:

Grouping by tenant:

select cycle_year , cycle_index , tenant_name, t.batch_id, t.batchType, sum(total_cost) total_cost
		from (
			select b.id as batch_id, brt.mdm_name tenant_name, b.cycle_year, b.cycle_index, concat(cycle_year, '-0', cycle_index, '-', '01') date, ii.resource_name, ii.total_cost,
			concat(cycle_year, '-', cycle_index, ': ', visibility_status) as batchType,
			rank() over (partition by cycle_year, cycle_index order by b.created_at  desc) as rnk
			from batch b
			inner join batch_invoice bi on bi.batch_id  = b.id
			inner join batch_invoice_item ii on ii.batch_invoice_id = bi.id 
			left join batch_raw_tenant brt on brt.batch_id = ii.batch_id and brt.mdm_name = ii.tenant_name 
			left join batch_raw_organization bro on bro.batch_id = ii.batch_id and bro.mdm_id = brt.mdm_org_id 
			--inner join batch_raw_carol_app brca on brca.batch_id = ii.batch_id and brca.mdm_tenant_id = brt.mdm_id 
			where 1=1 
			--and brca.mdm_name in ('','clockinapp')
			and b.id in (select id from (select id, cycle_year , cycle_index , created_at , rank() over (partition by cycle_year, cycle_index order by created_at  desc) as rnk from batch b ) t where rnk = 1)
			--and bro.mdm_name in ('totvstechfin','totvstechfinstaging','totvstechfindev')
			and bi.billing_account_id  in (select id from billing_account ba where name = 'TOTVSSupply')
		) t
		group by cycle_year , cycle_index , tenant_name, t.batch_id, t.batchType
		order by 6 desc

Grouping by tenant/services

select cycle_year, cycle_index, concat(cycle_year, '-0', cycle_index, '-', '01') date, resource_name, sum(total_cost) total_cost, batchType
	from (
		--select cycle_year , cycle_index , tenant_name, t.batch_id, t.batchType, sum(total_cost) total_cost
		--from (
			select b.id as batch_id, brt.mdm_name tenant_name, b.cycle_year, b.cycle_index, concat(cycle_year, '-0', cycle_index, '-', '01') date, ii.resource_name, ii.total_cost,
			concat(cycle_year, '-', cycle_index, ': ', visibility_status) as batchType,
			rank() over (partition by cycle_year, cycle_index order by b.created_at  desc) as rnk
			from batch b
			inner join batch_invoice bi on bi.batch_id  = b.id
			inner join batch_invoice_item ii on ii.batch_invoice_id = bi.id 
			left join batch_raw_tenant brt on brt.batch_id = ii.batch_id and brt.mdm_name = ii.tenant_name 
			left join batch_raw_organization bro on bro.batch_id = ii.batch_id and bro.mdm_id = brt.mdm_org_id 
			--inner join batch_raw_carol_app brca on brca.batch_id = ii.batch_id and brca.mdm_tenant_id = brt.mdm_id 
			where 1=1 
			--and brca.mdm_name in ('','clockinapp')
			and b.id in (select id from (select id, cycle_year , cycle_index , created_at , rank() over (partition by cycle_year, cycle_index order by created_at  desc) as rnk from batch b ) t where rnk = 1)
			--and bro.mdm_name in ('totvstechfin','totvstechfinstaging','totvstechfindev')
			and bi.billing_account_id  in (select id from billing_account ba where name = 'TOTVSSupply')
		--) t
		--group by cycle_year , cycle_index , tenant_name, t.batch_id, t.batchType
		--order by 6 desc
	) t
	where t.rnk = 1
	group by cycle_year , cycle_index , resource_name, t.batch_id, t.batchType
	order by 1,2,3,4