1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| select * from (select a.cd_cost_center,a.txt_quotefield as Chantier,substr(:p1,1,20) as Date1,substr(:p2,1,20)as Date2,sum(V.ACHAT)+sum(V.OPERATION)+sum(V.OCCUPATION)+sum(V.STOCK) as Total from cost_center A,
(select p.cd_cost_center SECTION,sum(round(p.rate_price_convert*to_number(decode(f.bo_credit_note,'1','-1','1'))*i.pr_total_ht_inv + p.rate_price_convert*to_number(decode(f.bo_credit_note,'1','-1','1'))*
((decode(f.val_inv_cost1,'','0',f.val_inv_cost1))+(decode(f.val_inv_cost2,'','0',f.val_inv_cost2))+(decode(f.val_inv_cost3,'','0',f.val_inv_cost3)))*(i.pr_total_ht_inv/f.val_inv_ht),2))
ACHAT,
0 OPERATION,
0 OCCUPATION,
0 STOCK
from invoiceline i, invoice f,prl p
where f.cd_invoice = i.cd_invoice and i.cd_prl = p.cd_prl and dt_accountant >= to_date(:p1,'MMYYYY') and dt_accountant < add_months(to_date(:p2,'MMYYYY'),1) and f.typ_inv_status = 2
group by p.cd_cost_center union
select ws.cd_cost_center, 0, sum(nvl(wp.pr_cost,0)) OPERATION, 0,0 from ws_process wp, ws ws where ws.cd_wo = wp.cd_wo and ws.cd_ws = wp.cd_ws and wp.dttm_process_real >= to_date(:p1,'MMYYYY') and wp.dttm_process_real < add_months(to_date(:p2,'MMYYYY'),1)
group by ws.cd_cost_center union
select ws.cd_cost_center,0,0,sum(nvl((oc.tm_occupation/100000)* oc.pr_hour_cost,0)) OCCUPATION,0 from occupation oc, ws ws where ws.cd_wo = oc.cd_wo and ws.cd_ws = oc.cd_ws and oc.dt_occupation >= to_date(:p1,'MMYYYY') and oc.dt_occupation < add_months(to_date(:p2,'MMYYYY'),1)
group by ws.cd_cost_center union
select st.cd_cost_center,0,0,0,sum(nvl(st.pr_stock*(-1),0)) STOCK from stock_mouvemt st where st.dttm_stock_mvt >= to_date(:p1,'MMYYYY') and st.dttm_stock_mvt < add_months(to_date(:p2,'MMYYYY'),1) and st.cd_cost_center is not null
group by st.cd_cost_center) V
where a.cd_cost_center = v.section (+) /*###*/
group by a.cd_cost_center,a.txt_quotefield,substr(:p1,1,20),substr(:p2,1,20)) where cd_cost_center = abc |
Partager