Report 2 and 3 type updated

This commit is contained in:
root 2022-09-20 20:04:00 +05:30
parent 466b38577a
commit 2510dd2c4d
1 changed files with 21 additions and 35 deletions

View File

@ -210,9 +210,9 @@ data2 as (
pro_data.expenses_amt
UNION
SELECT
drange_data1.start_date,
drange_data1.end_date,
drange_data1.project_id,
TO_CHAR(start_datetime, 'YYYY-MM-01')::date as start_date,
(date_trunc('month', end_datetime) + interval '1 month' - interval '1 day')::date as end_date,
pro_data.pproject_id as project_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -221,7 +221,7 @@ SELECT
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.employee_id,
AAL.id as timesheet_id,
AAL.start_datetime as timesheet_sdatetime,
0 as overall_budgeted_revenue,
@ -236,20 +236,13 @@ SELECT
0 AS expenses_amt,
((AAL.unit_amount * pro_data.pro_hourly_rate) - (AAL.amount * -1)) AS profit_amt,
((AAL.unit_amount * pro_data.pro_hourly_rate) - (AAL.amount * -1))/NULLIF((AAL.unit_amount * pro_data.pro_hourly_rate),0) AS profit_per
FROM drange_data1
left join pro_data on pro_data.pproject_id = drange_data1.project_id
left join account_analytic_line AAL on AAL.project_id=drange_data1.project_id and AAL.employee_id=drange_data1.employee_id
and AAL.start_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
>= drange_data1.start_date::date + '00:00:00'::time AT TIME ZONE 'UTC'
and AAL.end_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
<= drange_data1.end_date::date + '23:59:59'::time AT TIME ZONE 'UTC'
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_no_limit' and COALESCE(pro_data.is_sub_project, FALSE) = False
group by
drange_data1.start_date,
drange_data1.end_date,
pro_data.pro_sdate,
pro_data.pro_edate,
drange_data1.project_id,
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -257,12 +250,12 @@ SELECT
AAL.sub_project,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.employee_id,
AAL.id,
AAL.start_datetime,
pro_data.pro_hourly_rate,
aal.unit_amount,
aal.amount,
AAL.unit_amount,
AAL.amount,
pro_data.budgeted_hours,
pro_data.expenses_amt
),
@ -358,9 +351,9 @@ SELECT
pro_data.partner_id
UNION
SELECT
drange_data1.start_date,
drange_data1.end_date,
drange_data1.project_id,
TO_CHAR(start_datetime, 'YYYY-MM-01')::date as start_date,
(date_trunc('month', end_datetime) + interval '1 month' - interval '1 day')::date as end_date,
pro_data.pproject_id as project_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -369,7 +362,7 @@ SELECT
cons_data1.role,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.employee_id,
AAL.id as timesheet_id,
AAL.start_datetime as timesheet_sdatetime,
0 as overall_budgeted_revenue,
@ -387,25 +380,18 @@ SELECT
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)) - 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 account_analytic_line AAL on AAL.project_id=tsheet_data1.project_id and AAL.employee_id=tsheet_data1.employee_id
and AAL.start_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
>= drange_data1.start_date::date + '00:00:00'::time AT TIME ZONE 'UTC'
and AAL.end_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
<= drange_data1.end_date::date + '23:59:59'::time AT TIME ZONE 'UTC'
left join cons_data1 on cons_data1.project_id=drange_data1.project_id and cons_data1.employee_id=drange_data1.employee_id
FROM pro_data
left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id
left join cons_data1 on cons_data1.project_id=AAL.project_id and cons_data1.employee_id=AAL.employee_id
and AAL.start_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
>= cons_data1.start_date::date + '00:00:00'::time AT TIME ZONE 'UTC'
and AAL.end_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
<= cons_data1.end_date::date + '23:59:59'::time AT TIME ZONE 'UTC'
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant' and COALESCE(pro_data.is_sub_project, FALSE) = False
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
and COALESCE(pro_data.is_sub_project, FALSE) = False
group by
drange_data1.start_date,
drange_data1.end_date,
drange_data1.project_id,
drange_data1.employee_id,
pro_data.pproject_id,
AAL.employee_id,
AAL.id,
AAL.start_datetime,
pro_data.project_active,