overall bud reve report updated

This commit is contained in:
root 2022-08-30 12:54:48 +05:30
parent 6cdc76a02e
commit 4ca38c471e
2 changed files with 68 additions and 73 deletions

View File

@ -58,7 +58,8 @@ with pro_data as (
PRO.active as project_active,
PRO.project_type,
PRO.pricing_type,
(select PRO.id from project_subproject_rel as PAR where PRO.id=PAR.project_id limit 1) as parent_project,
(select project_id from project_subproject_rel as par where pro.id=par.id limit 1) as parent_project,
--(select PRO.id from project_subproject_rel as PAR where PRO.id=PAR.project_id limit 1) as parent_project,
STRING_AGG(distinct tag_master.name, ', ') as tag_name,
PRO.partner_id AS partner_id,
PRO.budgeted_revenue as budgeted_revenue,
@ -169,9 +170,9 @@ data1 as (
),
data2 as (
SELECT
coalesce(pro_data.pro_sdate, drange_data1.start_date) as start_date,
coalesce(pro_data.pro_edate, drange_data1.end_date) as end_date,
drange_data1.project_id,
coalesce(min(pro_data.pro_sdate), min(AAL.start_datetime::date)) as start_date,
coalesce(max(pro_data.pro_edate), max(AAL.end_datetime::date)) as end_date,
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -183,10 +184,10 @@ data2 as (
--pro_tsheet.timesheet_id,
null::int AS employee_id,
0 as overall_budgeted_revenue,
pro_data.budgeted_revenue,
pro_data.budgeted_hours,
0 as budgeted_revenue,
0 as budgeted_hours,
0 as overall_hourly_rate,
0 AS pro_hourly_rate,
pro_data.pro_hourly_rate,
0 as unit_amount,
0 as timesheet_cost,
0.0 AS actual_revenue,
@ -194,15 +195,16 @@ data2 as (
pro_data.expenses_amt,
0.0 AS profit_amt,
0.0 AS profit_per
FROM drange_data1
left join pro_data on pro_data.pproject_id = drange_data1.project_id
FROM pro_data
--left join pro_data on pro_data.pproject_id = drange_data1.project_id
left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id
WHERE pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_no_limit'
group by
drange_data1.start_date,
drange_data1.end_date,
pro_data.pro_sdate,
pro_data.pro_edate,
drange_data1.project_id,
--drange_data1.start_date,
--drange_data1.end_date,
--pro_data.pro_sdate,
--pro_data.pro_edate,
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -210,9 +212,9 @@ data2 as (
sub_project,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
pro_data.budgeted_revenue,
pro_data.budgeted_hours,
--drange_data1.employee_id,
--pro_data.budgeted_revenue,
pro_data.pro_hourly_rate,
pro_data.expenses_amt
UNION
SELECT
@ -263,11 +265,52 @@ SELECT
pro_data.pro_hourly_rate,
aal.unit_amount,
aal.amount,
pro_data.budgeted_revenue,
--pro_data.budgeted_revenue,
pro_data.budgeted_hours,
pro_data.expenses_amt
),
data3 as (
SELECT
coalesce(min(pro_data.pro_sdate), min(AAL.start_datetime::date)) as start_date,
coalesce(max(pro_data.pro_edate), max(AAL.end_datetime::date)) as end_date,
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
pro_data.parent_project,
null::int as sub_project,
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
null::int AS employee_id,
pro_data.budgeted_revenue as overall_budgeted_revenue,
0 as budgeted_revenue,
0 as budgeted_hours,
0 as overall_hourly_rate,
pro_data.pro_hourly_rate,
0 as unit_amount,
0 as timesheet_cost,
0.0 AS actual_revenue,
0 as actual_cost,
pro_data.expenses_amt,
0.0 AS profit_amt,
0.0 AS profit_per
FROM pro_data
left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
group by
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
pro_data.parent_project,
--sub_project,
pro_data.tag_name,
pro_data.partner_id,
pro_data.budgeted_revenue,
pro_data.pro_hourly_rate,
pro_data.expenses_amt
UNION
SELECT
drange_data1.start_date,
drange_data1.end_date,
@ -290,7 +333,7 @@ SELECT
coalesce(((AAL.amount * -1)/NULLIF(AAL.unit_amount, 0)), cons_data1.cons_timesheet_cost) as timesheet_cost,
(AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) as actual_revenue,
coalesce((AAL.amount * -1), cons_data1.cons_timesheet_cost, 0) as actual_cost,
pro_data.expenses_amt as expenses_amt,
0 as expenses_amt,
(AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) as profit_amt,
((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0))/NULLIF((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)),0)) * 100
as profit_per
@ -314,63 +357,14 @@ SELECT
pro_data.tag_name,
pro_data.pricing_type,
pro_data.partner_id,
pro_data.pro_hourly_rate,
pro_data.expenses_amt,
--pro_data.pro_hourly_rate,
--pro_data.expenses_amt,
AAL.unit_amount,
AAL.amount,
cons_data1.cons_timesheet_cost,
cons_data1.cons_hourly_cost,
pro_data.budgeted_revenue,
pro_data.pro_hourly_rate
UNION
SELECT
drange_data2.start_date,
drange_data2.end_date,
drange_data2.project_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
pro_data.parent_project,
null::int as sub_project,
cons_data1.role,
pro_data.tag_name,
pro_data.partner_id,
drange_data2.employee_id,
0 as overall_budgeted_revenue,
cons_data1.budgeted_revenue,
cons_data1.budgeted_hours,
pro_data.budgeted_revenue as overall_hourly_rate,
pro_data.pro_hourly_rate,
0 as unit_amount,
0 as timesheet_cost,
0.0 as actual_revenue,
0.0 as actual_cost,
pro_data.expenses_amt as expenses_amt,
0.0 as profit_amt,
0.0 as profit_per
FROM drange_data2
left join pro_data on pro_data.pproject_id=drange_data2.project_id
left join cons_data1 on cons_data1.project_id=drange_data2.project_id and cons_data1.employee_id=drange_data2.employee_id
and cons_data1.start_date >= drange_data2.start_date and cons_data1.end_date <= drange_data2.end_date
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
group by
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
pro_data.parent_project,
sub_project,
cons_data1.role,
pro_data.tag_name,
pro_data.partner_id,
drange_data2.start_date,
drange_data2.end_date,
drange_data2.project_id,
drange_data2.employee_id,
pro_data.budgeted_revenue,
pro_data.pro_hourly_rate,
cons_data1.budgeted_revenue,
cons_data1.budgeted_hours,
pro_data.expenses_amt
cons_data1.cons_hourly_cost
--pro_data.budgeted_revenue,
--pro_data.pro_hourly_rate
),
invoice_data as (SELECT
invoice_date.date as start_date,

View File

@ -45,6 +45,7 @@
<field name="parent_project"/>
<field name="sub_project"/>
<field name="employee_id"/>
<field name="overall_budgeted_revenue"/>
<field name="budgeted_revenue"/>
<field name="actual_revenue"/>
<field name="actual_cost"/>