'select coalesce(round(sum(amount)), 0) from im_costs where cost_type_id = 3700 and effective_date between now()::date-60 and now()::date-30',
'select coalesce(round(sum(amount)), 0) from im_costs where cost_type_id in (select * from im_sub_categories(3700)) and effective_date between now()::date-60 and now()::date-30',
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3700)) and effective_date between now()::date-60 and now()::date-30) as invoices,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3702)) and effective_date between now()::date-60 and now()::date-30) as quotes,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3704)) and effective_date between now()::date-60 and now()::date-30) as bills,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3706)) and effective_date between now()::date-60 and now()::date-30) as pos,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3718)) and effective_date between now()::date-60 and now()::date-30) as timesheet,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3720)) and effective_date between now()::date-60 and now()::date-30) as expenses
) base;'
wherereport_name='Net Margin Two Months Ago';
updateim_indicatorsset
indicator_section_id=15200
whereindicator_id=v_id;
...
...
@@ -174,24 +175,26 @@ BEGIN
'prelim_bruto_margin',
15110,
15000,
'select
round((quotes - pos) / (quotes+0.000001) * 100,1) as prelim_brut_margin
from
(select
(select sum(amount) from im_costs where cost_type_id = 3700 and effective_date between now()::date-60 and now()::date-30) as invoices,
(select sum(amount) from im_costs where cost_type_id = 3702 and effective_date between now()::date-60 and now()::date-30) as quotes,
(select sum(amount) from im_costs where cost_type_id = 3704 and effective_date between now()::date-60 and now()::date-30) as bills,
(select sum(amount) from im_costs where cost_type_id = 3706 and effective_date between now()::date-60 and now()::date-30) as pos,
(select sum(amount) from im_costs where cost_type_id = 3718 and effective_date between now()::date-60 and now()::date-30) as timesheet,
(select sum(amount) from im_costs where cost_type_id = 3720 and effective_date between now()::date-60 and now()::date-30) as expenses
) base
;',
'select 1',
0,
60,
5
);
updateim_reports
setreport_sql='select
round((quotes - pos) / (quotes+0.000001) * 100,1) as prelim_brut_margin
from
(select
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3700)) and effective_date between now()::date-60 and now()::date-30) as invoices,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3702)) and effective_date between now()::date-60 and now()::date-30) as quotes,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3704)) and effective_date between now()::date-60 and now()::date-30) as bills,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3706)) and effective_date between now()::date-60 and now()::date-30) as pos,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3718)) and effective_date between now()::date-60 and now()::date-30) as timesheet,
(select sum(amount) from im_costs where cost_type_id in (select * from im_sub_categories(3720)) and effective_date between now()::date-60 and now()::date-30) as expenses
) base;'
wherereport_name='Preliminary Bruto Margin Two Months Ago';