report query updated
This commit is contained in:
parent
df0cc07911
commit
699d9376fb
|
@ -340,7 +340,8 @@ SELECT
|
|||
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
|
||||
--and cons_data1.start_date >= drange_data2.start_date and cons_data1.end_date <= drange_data2.end_date
|
||||
and drange_data2.start_date >= cons_data1.start_date and drange_data2.end_date <= cons_data1.end_date
|
||||
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
|
||||
group by
|
||||
drange_data2.start_date,
|
||||
|
@ -380,17 +381,24 @@ SELECT
|
|||
0 as pro_hourly_rate,
|
||||
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,
|
||||
--coalesce((AAL.amount * -1), cons_data1.cons_timesheet_cost, 0) as actual_cost,
|
||||
case when cons_data1.cons_timesheet_cost is null then (AAL.amount * -1) else (AAL.unit_amount * cons_data1.cons_timesheet_cost)
|
||||
end as actual_cost,
|
||||
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
|
||||
--(AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) as profit_amt,
|
||||
(AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) - case when cons_data1.cons_timesheet_cost is null
|
||||
then (AAL.amount * -1) else (AAL.unit_amount * cons_data1.cons_timesheet_cost) end 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,
|
||||
(((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) - case when cons_data1.cons_timesheet_cost is null then (AAL.amount * -1)
|
||||
else (AAL.unit_amount * cons_data1.cons_timesheet_cost) end) / NULLIF((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)), 0)) * 100 as profit_per
|
||||
FROM drange_data1
|
||||
left join pro_data on pro_data.pproject_id = drange_data1.project_id
|
||||
left join tsheet_data1 on tsheet_data1.project_id=drange_data1.project_id and tsheet_data1.employee_id=drange_data1.employee_id
|
||||
left join cons_data1 on cons_data1.project_id=drange_data1.project_id and cons_data1.employee_id=drange_data1.employee_id
|
||||
left join account_analytic_line AAL on AAL.project_id=tsheet_data1.project_id and AAL.employee_id=tsheet_data1.employee_id
|
||||
and AAL.start_datetime::date >= drange_data1.start_date and AAL.end_datetime::date <= drange_data1.end_date
|
||||
left join cons_data1 on cons_data1.project_id=drange_data1.project_id and cons_data1.employee_id=drange_data1.employee_id
|
||||
and AAL.start_datetime::date >= cons_data1.start_date and AAL.end_datetime::date <= cons_data1.end_date
|
||||
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
|
||||
group by
|
||||
drange_data1.start_date,
|
||||
|
@ -407,14 +415,10 @@ SELECT
|
|||
pro_data.tag_name,
|
||||
pro_data.pricing_type,
|
||||
pro_data.partner_id,
|
||||
--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
|
||||
),
|
||||
invoice_data as (SELECT
|
||||
invoice_date.date as start_date,
|
||||
|
|
Loading…
Reference in New Issue