CREATE OR REPLACE VIEW V8_REP_YBLD_PICKUP_XCMA
AS 
select
   ybld_date,
   yblh_xcma_id XCMA_ID,
   sum(def_pickupnoofrooms) defnoofrooms,
   sum(def_picknoofadults) defnoofadults,
   sum(tent_pickupnoofrooms) tentnoofrooms,
   sum( tent_picknoofadults) tentnoofadults
from 
(select 
 d.ybld_id,
 d.ybld_ycat_id,
 nvl((select sum(ydet_noofrooms) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=0 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)=0),0)+nvl((select count( distinct ydet_sharenum) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=0 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)<>0),0) tent_pickupnoofrooms, 
 nvl((select sum(ydet_adultno) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=0 and ydet_ybld_id=d.ybld_id),0) tent_picknoofadults,
 nvl((select sum(ydet_noofrooms) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=1 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)=0),0)+nvl((select count( distinct ydet_sharenum) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=1 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)<>0),0) def_pickupnoofrooms, 
 nvl((select sum(ydet_adultno) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=1 and ydet_ybld_id=d.ybld_id),0) def_picknoofadults,
 ybld_actualnoofrooms,
 ybld_cutoffdate,
 ybld_date,
 ybld_yblh_id,
 ybld_expectednoofrooms
  from ybld d) ybld,yblh,ybst,fideliodate d, ycat
where
    ybld_yblh_id=yblh_id
and YBLH_YBST_ID=ybst_id
and YBST_RESSTATUS<>3
and ybld_ycat_id = ycat.ycat_id
group by ybld_date, yblh_xcma_id;


CREATE OR REPLACE VIEW V8_REP_YBLD_NOT_PICKUP_XCMA
AS 
select
   ybld_date,
   yblh_xcma_id XCMA_ID,
   sum(decode(ybst_resstatus,1,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),0)) defnoofrooms,
   sum(decode(ybst_resstatus,1,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),nvl(ybld_expectednoofrooms,0))) defnoofroomsbookingpos,
   sum(decode(ybst_resstatus,1,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms*nvl(ybld_noofadults,0)),0)) defnoofadults,
   sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),0)) tentnoofrooms,
   sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms-nvl(ybld_expectednoofrooms,0)),0)) tentnoofroomsbookingpos,
   sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms*nvl(ybld_noofadults,0)),0)) tentnoofadults
from
(select 
 d.ybld_id,
 D.ybld_ycat_id,
 ybld_actualnoofrooms-(nvl((select sum(ydet_noofrooms) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus<>3 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)=0),0)+nvl((select count( distinct ydet_sharenum) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus<>3 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)<>0),0)) ybld_actualnoofrooms, 
 ybld_noofadults-(nvl((select avg(ydet_adultno) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus<>3 and ydet_ybld_id=d.ybld_id),0)) ybld_noofadults,
 --ybld_actualnoofrooms,
 ybld_cutoffdate,
 ybld_date,
 ybld_yblh_id,
 ybld_expectednoofrooms
  from ybld d) ybld,yblh,ybst,fideliodate d, ycat
where
    ybld_yblh_id=yblh_id
and YBLH_YBST_ID=ybst_id
and YBST_RESSTATUS<>3
and YBLD_YCAT_ID = ycat_id
group by ybld_date, yblh_xcma_id;

CREATE OR REPLACE VIEW V8_REP_YBLD_PICKUP_XCMA_CAD
AS 
select
   ybld_date,
   yblh_xcma_id XCMA_ID,
   YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID YCAD_ID,
   sum(def_pickupnoofrooms) defnoofrooms,
   sum(def_picknoofadults) defnoofadults,
   sum(tent_pickupnoofrooms) tentnoofrooms,
   sum( tent_picknoofadults) tentnoofadults
from 
(select 
 d.ybld_id,
 d.ybld_ycat_id,
 nvl((select sum(ydet_noofrooms) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=0 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)=0),0)+nvl((select count( distinct ydet_sharenum) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=0 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)<>0),0) tent_pickupnoofrooms, 
 nvl((select sum(ydet_adultno) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=0 and ydet_ybld_id=d.ybld_id),0) tent_picknoofadults,
 nvl((select sum(ydet_noofrooms) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=1 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)=0),0)+nvl((select count( distinct ydet_sharenum) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=1 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)<>0),0) def_pickupnoofrooms, 
 nvl((select sum(ydet_adultno) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus=1 and ydet_ybld_id=d.ybld_id),0) def_picknoofadults,
 ybld_actualnoofrooms,
 ybld_cutoffdate,
 ybld_date,
 ybld_yblh_id,
 ybld_expectednoofrooms
  from ybld d) ybld,yblh,ybst,fideliodate d, ycat
where
    ybld_yblh_id=yblh_id
and YBLH_YBST_ID=ybst_id
and YBST_RESSTATUS<>3
and ybld_ycat_id = ycat.ycat_id
group by ybld_date, yblh_xcma_id, YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID;


CREATE OR REPLACE VIEW V8_REP_YBLD_NO_PICKUP_XCMA_CAD
AS 
select
   ybld_date,
   yblh_xcma_id XCMA_ID,
   YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID YCAD_ID,
   sum(decode(ybst_resstatus,1,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),0)) defnoofrooms,
   sum(decode(ybst_resstatus,1,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),nvl(ybld_expectednoofrooms,0))) defnoofroomsbookingpos,
   sum(decode(ybst_resstatus,1,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms*nvl(ybld_noofadults,0)),0)) defnoofadults,
   sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),0)) tentnoofrooms,
   sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms-nvl(ybld_expectednoofrooms,0)),0)) tentnoofroomsbookingpos,
   sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms*nvl(ybld_noofadults,0)),0)) tentnoofadults
from
(select 
 d.ybld_id,
 D.ybld_ycat_id,
 ybld_actualnoofrooms-(nvl((select sum(ydet_noofrooms) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus<>3 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)=0),0)+nvl((select count( distinct ydet_sharenum) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus<>3 and ydet_ybld_id=d.ybld_id and  nvl(ydet_sharenum,0)<>0),0)) ybld_actualnoofrooms, 
 ybld_noofadults-(nvl((select avg(ydet_adultno) from ydet,yres where ydet_yres_id=yres_id and yres_resstatus<>3 and ydet_ybld_id=d.ybld_id),0)) ybld_noofadults,
 --ybld_actualnoofrooms,
 ybld_cutoffdate,
 ybld_date,
 ybld_yblh_id,
 ybld_expectednoofrooms
  from ybld d) ybld,yblh,ybst,fideliodate d, ycat
where
    ybld_yblh_id=yblh_id
and YBLH_YBST_ID=ybst_id
and YBST_RESSTATUS<>3
and YBLD_YCAT_ID = ycat_id
group by ybld_date, yblh_xcma_id, YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID;

CREATE OR REPLACE VIEW V8_REP_REV_FORECAST_HUGE
AS 
SELECT 0 typenum,'defres' typename,YPOS.ypos_id,YPOS.ypos_xcms_id,YPOS.ypos_yres_id,0 yblh_id,YPOS.ypos_date,YPOS.ypos_zdco_id,YPOS.ypos_unitprice,YPOS.ypos_quantity,ypos.ypos_quantity quantity_bookingpos,YPOS.ypos_taxlink_id,YPOS.ypos_internalsplit_id,YPOS.ypos_dt,YPOS.ypos_type,
YDET.YDET_XCMA_ID XCMA_ID,
(select xcma.XCMA_XCMM_ID from xcma where xcma.XCMA_ID=ydet.YDET_XCMA_ID) XCMM_ID,
(SELECT YRAL.YRAL_YRAS_ID FROM YRAL WHERE YRAL.YRAL_YDET_ID=YDET.YDET_ID AND YRAL.YRAL_YRAC_ID=1 AND ROWNUM=1) YRAS_SOURCE_ID,
(SELECT YRAL.YRAL_YRAS_ID FROM YRAL WHERE YRAL.YRAL_YDET_ID=YDET.YDET_ID AND YRAL.YRAL_YRAC_ID=2 AND ROWNUM=1) YRAS_CHANNEL_ID, 
YDET.YDET_YRCH_ID YRCH_ID,
(SELECT ZDCO.ZDCO_STATS_TYPE FROM ZDCO WHERE ZDCO.ZDCO_ID=(SELECT ypos_s.YPOS_ZDCO_ID FROM YPOS ypos_s WHERE ypos_s.YPOS_TAXLINK_ID=YPOS.YPOS_TAXLINK_ID AND ypos_s.YPOS_DT=1 AND ROWNUM=1)) ZDCO_STATS_TYPE,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=1 AND ROWNUM=1) COMPANY_ID,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=2 AND ROWNUM=1) TRAVEL_ID,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=3 AND ROWNUM=1) SOURCE_ID,
YDET.YDET_YCAT_ID,
(SELECT YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID FROM YCAT WHERE YCAT.YCAT_ID=YDET.YDET_YCAT_ID) YCAD_ID
FROM YPOS,YRES,YDET
WHERE yres_id=ypos_yres_id
AND yres_resstatus=1
AND ydet_yres_id=yres_id
AND ydet_date=ypos_date
AND NVL(ydet_ybld_id,0)= 0
AND ydet_date>=V8_sys_fideliodate
UNION ALL
SELECT 1 typenum,'tentres' typename,YPOS.ypos_id,YPOS.ypos_xcms_id,YPOS.ypos_yres_id,0 yblh_id,YPOS.ypos_date,YPOS.ypos_zdco_id,YPOS.ypos_unitprice,YPOS.ypos_quantity,ypos.ypos_quantity quantity_bookingpos,YPOS.ypos_taxlink_id,YPOS.ypos_internalsplit_id,YPOS.ypos_dt,YPOS.ypos_type,
YDET.YDET_XCMA_ID XCMA_ID,
(select xcma.XCMA_XCMM_ID from xcma where xcma.XCMA_ID=ydet.YDET_XCMA_ID) XCMM_ID,
(SELECT YRAL.YRAL_YRAS_ID FROM YRAL WHERE YRAL.YRAL_YDET_ID=YDET.YDET_ID AND YRAL.YRAL_YRAC_ID=1 AND ROWNUM=1) YRAS_SOURCE_ID,
(SELECT YRAL.YRAL_YRAS_ID FROM YRAL WHERE YRAL.YRAL_YDET_ID=YDET.YDET_ID AND YRAL.YRAL_YRAC_ID=2 AND ROWNUM=1) YRAS_CHANNEL_ID, 
YDET.YDET_YRCH_ID YRCH_ID,
(SELECT ZDCO.ZDCO_STATS_TYPE FROM ZDCO WHERE ZDCO.ZDCO_ID=(SELECT ypos_s.YPOS_ZDCO_ID FROM YPOS ypos_s WHERE ypos_s.YPOS_TAXLINK_ID=YPOS.YPOS_TAXLINK_ID AND ypos_s.YPOS_DT=1 AND ROWNUM=1)) ZDCO_STATS_TYPE,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=1 AND ROWNUM=1) COMPANY_ID,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=2 AND ROWNUM=1) TRAVEL_ID,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=3 AND ROWNUM=1) SOURCE_ID,
YDET.YDET_YCAT_ID,
(SELECT YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID FROM YCAT WHERE YCAT.YCAT_ID=YDET.YDET_YCAT_ID) YCAD_ID
FROM YPOS,YRES,YDET
WHERE yres_id=ypos_yres_id
AND yres_resstatus=0
AND ydet_yres_id=yres_id
AND ydet_date=ypos_date
AND NVL(ydet_ybld_id,0)= 0
AND ydet_date>=V8_sys_fideliodate
UNION ALL
SELECT 2 typenum,'defpickup' typename,YPOS.ypos_id,YPOS.ypos_xcms_id,YPOS.ypos_yres_id,0 yblh_id,YPOS.ypos_date,YPOS.ypos_zdco_id,YPOS.ypos_unitprice,YPOS.ypos_quantity,ypos.ypos_quantity quantity_bookingpos,YPOS.ypos_taxlink_id,YPOS.ypos_internalsplit_id,YPOS.ypos_dt,ypos_type,
YDET.YDET_XCMA_ID XCMA_ID,
(select xcma.XCMA_XCMM_ID from xcma where xcma.XCMA_ID=ydet.YDET_XCMA_ID) XCMM_ID,
(SELECT YRAL.YRAL_YRAS_ID FROM YRAL WHERE YRAL.YRAL_YDET_ID=YDET.YDET_ID AND YRAL.YRAL_YRAC_ID=1 AND ROWNUM=1) YRAS_SOURCE_ID,
(SELECT YRAL.YRAL_YRAS_ID FROM YRAL WHERE YRAL.YRAL_YDET_ID=YDET.YDET_ID AND YRAL.YRAL_YRAC_ID=2 AND ROWNUM=1) YRAS_CHANNEL_ID, 
YDET.YDET_YRCH_ID YRCH_ID,
(SELECT ZDCO.ZDCO_STATS_TYPE FROM ZDCO WHERE ZDCO.ZDCO_ID=(SELECT ypos_s.YPOS_ZDCO_ID FROM YPOS ypos_s WHERE ypos_s.YPOS_TAXLINK_ID=YPOS.YPOS_TAXLINK_ID AND ypos_s.YPOS_DT=1 AND ROWNUM=1)) ZDCO_STATS_TYPE,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=1 AND ROWNUM=1) COMPANY_ID,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=2 AND ROWNUM=1) TRAVEL_ID,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=3 AND ROWNUM=1) SOURCE_ID,
YDET.YDET_YCAT_ID,
(SELECT YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID FROM YCAT WHERE YCAT.YCAT_ID=YDET.YDET_YCAT_ID) YCAD_ID
FROM YPOS,YRES,YDET
WHERE yres_id=ypos_yres_id
AND yres_resstatus=1
AND ydet_yres_id=yres_id
AND ydet_date=ypos_date
AND NVL(ydet_ybld_id,0)<>0
AND ydet_date>=V8_sys_fideliodate
UNION ALL
SELECT 3 typenum,'tentpickup' typename,YPOS.ypos_id,YPOS.ypos_xcms_id,YPOS.ypos_yres_id,0 yblh_id,YPOS.ypos_date,YPOS.ypos_zdco_id,YPOS.ypos_unitprice,YPOS.ypos_quantity,ypos.ypos_quantity quantity_bookingpos,YPOS.ypos_taxlink_id,YPOS.ypos_internalsplit_id,YPOS.ypos_dt,YPOS.ypos_type,
YDET.YDET_XCMA_ID XCMA_ID,
(select xcma.XCMA_XCMM_ID from xcma where xcma.XCMA_ID=ydet.YDET_XCMA_ID) XCMM_ID,
(SELECT YRAL.YRAL_YRAS_ID FROM YRAL WHERE YRAL.YRAL_YDET_ID=YDET.YDET_ID AND YRAL.YRAL_YRAC_ID=1 AND ROWNUM=1) YRAS_SOURCE_ID,
(SELECT YRAL.YRAL_YRAS_ID FROM YRAL WHERE YRAL.YRAL_YDET_ID=YDET.YDET_ID AND YRAL.YRAL_YRAC_ID=2 AND ROWNUM=1) YRAS_CHANNEL_ID, 
YDET.YDET_YRCH_ID YRCH_ID,
(SELECT ZDCO.ZDCO_STATS_TYPE FROM ZDCO WHERE ZDCO.ZDCO_ID=(SELECT ypos_s.YPOS_ZDCO_ID FROM YPOS ypos_s WHERE ypos_s.YPOS_TAXLINK_ID=YPOS.YPOS_TAXLINK_ID AND ypos_s.YPOS_DT=1 AND ROWNUM=1)) ZDCO_STATS_TYPE,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=1 AND ROWNUM=1) COMPANY_ID,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=2 AND ROWNUM=1) TRAVEL_ID,
(SELECT YCLN.YCLN_XCMS_ID FROM YCLN WHERE YCLN.YCLN_YDET_ID=YDET.YDET_ID AND YCLN.YCLN_XCCA_INTERNALCATEGORY=3 AND ROWNUM=1) SOURCE_ID,
YDET.YDET_YCAT_ID,
(SELECT YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID FROM YCAT WHERE YCAT.YCAT_ID=YDET.YDET_YCAT_ID) YCAD_ID
FROM YPOS,YRES,YDET
WHERE yres_id=ypos_yres_id
AND yres_resstatus=0
AND ydet_yres_id=yres_id
AND ydet_date=ypos_date
AND NVL(ydet_ybld_id,0)<> 0
AND ydet_date>=V8_sys_fideliodate
UNION ALL
SELECT 4 typenum,'defblock' typename,YBOS.ybos_id,0,0,YBOS.ybos_yblh_id yblh_id,YBOS.ybos_date,YBOS.ybos_zdco_id,YBOS.ybos_unitprice*YBOS.ybos_quantity,v.blockrooms-v.resrooms,
(case when V.RESROOMS>=V.YBLD_EXPECTEDNOOFROOMS then 0 else V.YBLD_EXPECTEDNOOFROOMS-V.RESROOMS end) ROOMS_BOOKINGPOS,
YBOS.ybos_taxlink_id,YBOS.ybos_internalsplit_id,YBOS.ybos_dt,YBOS.ybos_type,
YBLH.YBLH_XCMA_ID XCMA_ID,
(select xcma.XCMA_XCMM_ID from xcma where xcma.XCMA_ID=yblh.YBLH_XCMA_ID) XCMM_ID,
(SELECT YBAL.YBAL_YRAS_ID FROM YBAL,YRAS WHERE YBAL.YBAL_YRAS_ID=YRAS.YRAS_ID AND YBAL.YBAL_YBLH_ID=YBLH.YBLH_ID AND YRAS.YRAS_YRAC_ID=1 AND ROWNUM=1) YRAS_SOURCE_ID,
(SELECT YBAL.YBAL_YRAS_ID FROM YBAL,YRAS WHERE YBAL.YBAL_YRAS_ID=YRAS.YRAS_ID AND YBAL.YBAL_YBLH_ID=YBLH.YBLH_ID AND YRAS.YRAS_YRAC_ID=2 AND ROWNUM=1) YRAS_CHANNEL_ID, 
YBLH.YBLH_YRCH_ID YRCH_ID,
(SELECT ZDCO.ZDCO_STATS_TYPE FROM ZDCO WHERE ZDCO.ZDCO_ID=(SELECT ybos_s.YBOS_ZDCO_ID FROM YBOS ybos_s WHERE ybos_s.YBOS_TAXLINK_ID=YBOS.YBOS_TAXLINK_ID AND ybos_s.YBOS_DT=1 AND ROWNUM=1)) ZDCO_STATS_TYPE,
(SELECT YBCL.YBCL_XCMS_ID FROM YBCL WHERE YBCL.YBCL_YBLH_ID=YBLH.YBLH_ID AND YBCL.YBCL_INTERNALCATEGORY=1 AND ROWNUM=1) COMPANY_ID,
(SELECT YBCL.YBCL_XCMS_ID FROM YBCL WHERE YBCL.YBCL_YBLH_ID=YBLH.YBLH_ID AND YBCL.YBCL_INTERNALCATEGORY=2 AND ROWNUM=1) TRAVEL_ID,
(SELECT YBCL.YBCL_XCMS_ID FROM YBCL WHERE YBCL.YBCL_YBLH_ID=YBLH.YBLH_ID AND YBCL.YBCL_INTERNALCATEGORY=3 AND ROWNUM=1) SOURCE_ID,
YBLD.ybld_ycat_id,
(SELECT YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID FROM YCAT WHERE YCAT.YCAT_ID=YBLD.ybld_ycat_id) YCAD_ID
FROM YBOS,v8_rep_calcYbosWithAvl v,YBLH,YBST,YBLD
WHERE v.ybos_id=YBOS.ybos_id
AND yblh_id=ybos_yblh_id
AND ybst_id=yblh_ybst_id
AND ybst_resstatus=1
AND ybos_date>=V8_sys_fideliodate
AND ybos_ybld_id=ybld_id
UNION ALL
SELECT 5 typenum,'tentblock' typename,YBOS.ybos_id,0,0,YBOS.ybos_yblh_id yblh_id,YBOS.ybos_date,YBOS.ybos_zdco_id,YBOS.ybos_unitprice*YBOS.ybos_quantity,v.blockrooms-v.resrooms,
(case when V.RESROOMS>=V.YBLD_EXPECTEDNOOFROOMS then V.BLOCKROOMS-V.RESROOMS else V.BLOCKROOMS-V.YBLD_EXPECTEDNOOFROOMS end) ROOMS_BOOKINGPOS,
YBOS.ybos_taxlink_id,YBOS.ybos_internalsplit_id,YBOS.ybos_dt,YBOS.ybos_type,
YBLH.YBLH_XCMA_ID XCMA_ID,
(select xcma.XCMA_XCMM_ID from xcma where xcma.XCMA_ID=yblh.YBLH_XCMA_ID) XCMM_ID,
(SELECT YBAL.YBAL_YRAS_ID FROM YBAL,YRAS WHERE YBAL.YBAL_YRAS_ID=YRAS.YRAS_ID AND YBAL.YBAL_YBLH_ID=YBLH.YBLH_ID AND YRAS.YRAS_YRAC_ID=1 AND ROWNUM=1) YRAS_SOURCE_ID,
(SELECT YBAL.YBAL_YRAS_ID FROM YBAL,YRAS WHERE YBAL.YBAL_YRAS_ID=YRAS.YRAS_ID AND YBAL.YBAL_YBLH_ID=YBLH.YBLH_ID AND YRAS.YRAS_YRAC_ID=2 AND ROWNUM=1) YRAS_CHANNEL_ID, 
YBLH.YBLH_YRCH_ID YRCH_ID,
(SELECT ZDCO.ZDCO_STATS_TYPE FROM ZDCO WHERE ZDCO.ZDCO_ID=(SELECT ybos_s.YBOS_ZDCO_ID FROM YBOS ybos_s WHERE ybos_s.YBOS_TAXLINK_ID=YBOS.YBOS_TAXLINK_ID AND ybos_s.YBOS_DT=1 AND ROWNUM=1)) ZDCO_STATS_TYPE,
(SELECT YBCL.YBCL_XCMS_ID FROM YBCL WHERE YBCL.YBCL_YBLH_ID=YBLH.YBLH_ID AND YBCL.YBCL_INTERNALCATEGORY=1 AND ROWNUM=1) COMPANY_ID,
(SELECT YBCL.YBCL_XCMS_ID FROM YBCL WHERE YBCL.YBCL_YBLH_ID=YBLH.YBLH_ID AND YBCL.YBCL_INTERNALCATEGORY=2 AND ROWNUM=1) TRAVEL_ID,
(SELECT YBCL.YBCL_XCMS_ID FROM YBCL WHERE YBCL.YBCL_YBLH_ID=YBLH.YBLH_ID AND YBCL.YBCL_INTERNALCATEGORY=3 AND ROWNUM=1) SOURCE_ID,
YBLD.ybld_ycat_id,
(SELECT YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID FROM YCAT WHERE YCAT.YCAT_ID=YBLD.ybld_ycat_id) YCAD_ID
FROM YBOS,v8_rep_calcYbosWithAvl v,YBLH,YBST,YBLD
WHERE v.ybos_id=YBOS.ybos_id
AND yblh_id=ybos_yblh_id
AND ybst_id=yblh_ybst_id
AND ybst_resstatus=0
AND ybos_ybld_id=ybld_id
AND ybos_date>=V8_sys_fideliodate;

CREATE OR REPLACE VIEW V8_REP_YDET_OCC_WB_XCMA
AS 
select ydet_xcma_id,ydet_date,sum(defnoofrooms) defnoofrooms, sum(defnoofroomsDayUse) defnoofroomsDayUse, sum(tentnoofrooms) tentnoofrooms,sum(tentnoofroomsDayUse) tentnoofroomsDayUse, sum(tentblockdefresroom) tentblockdefresroom,sum(tentblockdefresroomDayUse) tentblockdefresroomDayUse from
 (
  select
   ydet_xcma_id,
   ydet_date,
           decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                  , sum(decode(ybst_resstatus,0,decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0),0))
                   -sum(decode(ybst_resstatus,1,decode(yres_resstatus,1,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end,0),0))
          ) defnoofrooms,
          sum(decode(yres_resstatus,1,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
          defnoofroomsDayUse,
          decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  , sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))          
                  ,-sum(decode(ybst_resstatus,0,decode(yres_resstatus,0,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end,0),0)) --substract tentative res only because definitive day use (and non day use) will be substrated by tentblockdefresroom
          ) tentnoofrooms,

          decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,sum(decode(yres_resstatus,0,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))          
                  ,sum(decode(ybst_resstatus,0,decode(yres_resstatus,0,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end,0),0))
                  )
          tentnoofroomsDayUse,
         decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,sum(decode(ybst_resstatus,0,decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0),0))
                  )
          tentblockdefresroom,
           decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,sum(decode(ybst_resstatus,0,decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0),0))
                  )
          tentblockdefresroomDayUse
 from ydet,yres,ybld,yblh,ybst,fideliodate d
 where
     ydet_yres_id=yres_id(+)
 and ydet_ybld_id=ybld_id(+)
 and ybld_yblh_id=yblh_id(+)
 and yblh_ybst_id=ybst_id(+)
 and yres_resstatus<>3
 --and yres_exparrtime<>yres_expdeptime
 and nvl(ydet_sharenum,0)=0
 group by ydet_xcma_id,ydet_date,ydet_sharenum,ybld_cutoffdate,d.WGBS_DATEVALUE
 union all
 select
   ydet_xcma_id,
   ydet_date,
		 decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then 1 else 0 end,0)))
                  ,decode(max(nvl(ybst_resstatus,0)),0,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then 1 else 0 end,0))),0)
                  )
          defnoofrooms,
          case when max(decode(yres_resstatus,1,yres_expdeptime-yres_exparrtime,0))=0 then 
          decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime=yres_expdeptime then 1 else 0 end,0)))
                  ,decode(max(nvl(ybst_resstatus,0)),0,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then 1 else 0 end,0))),0)
                  ) else 0 end
           defnoofroomsDayUse,
		  decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,decode(sum(yres_resstatus),0,sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then 1 else 0 end,0))),0)
                  ,0                              
                  )
          tentnoofrooms,
          case when max(yres_expdeptime-yres_exparrtime)=0
          then 
          decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,decode(sum(yres_resstatus),0,sum(decode(yres_resstatus,0,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,0,case when yres_exparrtime =yres_expdeptime then 1 else 0 end,0))),0)
                  ,0
                  )
          else 0 end
          tentnoofroomsDayUse,
		  decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,decode(max(nvl(ybst_resstatus,0)),0,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then 1 else 0 end,0))),0)
                  )
          tentblockdefresroom,
           case when max(decode(yres_resstatus,1,yres_expdeptime-yres_exparrtime,0))=0 then 
          decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,decode(max(nvl(ybst_resstatus,0)),0,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then 1 else 0 end,0))),0)
                  ) else 0 end
          tentBlockDefResroomDayUse
 from ydet,yres,ybld,yblh,ybst,fideliodate d
 where
     ydet_yres_id=yres_id(+)
 and ydet_ybld_id=ybld_id(+)
 and ybld_yblh_id=yblh_id(+)
 and yblh_ybst_id=ybst_id(+)
 and yres_resstatus<>3
 --and yres_exparrtime<>yres_expdeptime
 and nvl(ydet_sharenum,0)<>0
 group by ydet_xcma_id,ydet_date,ydet_sharenum,d.WGBS_DATEVALUE
 ) group by ydet_xcma_id,ydet_date;

 

CREATE OR REPLACE VIEW V8_REP_YDET_ADULT_WB_XCMA
AS 
select 
YDET_XCMA_ID,
ydet_date,
sum(defadultno) defadultno,
sum(defadultnoDayUse) defadultnoDayUse,
sum(tentadultno) tentadultno,
sum(tentadultnoDayUse) tentadultnoDayUse,
sum(defblocksubstract) defblocksubstract,
sum(tentblocksubstract) tentblocksubstract
from 
 (
  select
   ydet_xcma_id YDET_xcma_id,
   ydet_date
         ,sum(decode(yres_resstatus,1,case when yres_exparrtime<> yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) defadultno
         ,sum(decode(yres_resstatus,1,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms  else 0 end,0 *ydet_adultno)) defadultnoDayUse
         ,sum(decode(yres_resstatus,0,case when yres_exparrtime<> yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) tentadultno
         ,sum(decode(yres_resstatus,0,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) tentadultnoDayUse
         ,decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,avg(ydet_noofrooms)*(avg(decode(ybst_resstatus,1,nvl(ybld_noofadults,0),0)))) defblocksubstract 
         ,decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,avg(ydet_noofrooms)*(avg(decode(ybst_resstatus,0,nvl(ybld_noofadults,0),0)))) tentblocksubstract 
 from ydet,yres,ybld,yblh,ybst,fideliodate d,ycat
 where
     ydet_yres_id=yres_id(+)
 and ydet_ybld_id=ybld_id(+)
 and ybld_yblh_id=yblh_id(+)
 and yblh_ybst_id=ybst_id(+)
 and ydet_ycat_id=ycat_id
 and yres_resstatus<>3
 and yres.YRES_EXPDEPTIME>  (select * from HistoryFidelioDate)
-- and yres_exparrtime<>yres_expdeptime
 and nvl(ydet_sharenum,0)<>0
 group by ydet_sharenum,ydet_ycat_id,ydet_date,WGBS_DATEVALUE,ydet_xcma_id
 union all
  select
   ydet_xcma_id YDET_xcma_id,
   ydet_date
         ,sum(decode(yres_resstatus,1,case when yres_exparrtime<> yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) defadultno
         ,sum(decode(yres_resstatus,1,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) defadultnoDayUse
         ,sum(decode(yres_resstatus,0,case when yres_exparrtime<> yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) tentadultno
         ,sum(decode(yres_resstatus,0,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) tentadultnoDayUse
         ,decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,sum(decode(nvl(ybst_resstatus,0),1,ydet_noofrooms*nvl(ybld_noofadults,0),0))) defblocksubstract 
         ,decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,sum(decode(nvl(ybst_resstatus,0),0,ydet_noofrooms*nvl(ybld_noofadults,0),0))) tentblocksubstract 
 from ydet,yres,ybld,yblh,ybst,fideliodate d,ycat
 where
     ydet_yres_id=yres_id(+)
 and ydet_ybld_id=ybld_id(+)
 and ybld_yblh_id=yblh_id(+)
 and yblh_ybst_id=ybst_id(+)
 and ydet_ycat_id=ycat_id
 and yres_resstatus<>3
 and yres.YRES_EXPDEPTIME>  (select * from HistoryFidelioDate)  
-- and yres_exparrtime<>yres_expdeptime
 and nvl(ydet_sharenum,0)=0
 group by ydet_ycat_id,ydet_date,WGBS_DATEVALUE,ybld_cutoffdate,ydet_xcma_id
)
group by ydet_xcma_id,ydet_date;



CREATE OR REPLACE VIEW V8_REP_HS_ARR_ALLCHILD_XCMA
AS
select wdat_date
    ,xcma_id XCMA_ID
    ,xcma_xcmm_id xcmm_id
    ,nvl(sum(allarrchild),0) allarrchild
    ,nvl(sum(defarrchild),0) defarrchild
    ,nvl(sum(defarrchilddayuse),0) defarrchilddayuse
    ,nvl(sum(tentarrchild),0) tentarrchild 
    ,nvl(sum(tentarrchilddayuse),0) tentarrchilddayuse
   ,nvl(sum(allarrdomesticchild),0) allarrdomesticchild
   ,nvl(sum(defarrdomesticchild),0) defarrdomesticchild
   ,nvl(sum(tentarrdomesticchild),0) tentarrdomesticchild           
   ,nvl(sum(allarrfreeofchargechild),0) allarrfreeofchargechild
   ,nvl(sum(defarrfreeofchargechild),0) defarrfreeofchargechild
   ,nvl(sum(tentarrfreeofchargechild),0) tentarrfreeofchargechild           
from (
select 
   wdat_date
   ,xcma_id
   ,xcma_xcmm_id
   ,sum(yrgl_number*ydet_noofrooms) allarrchild
   ,sum(decode(xcac_domestic,1,yrgl_number*ydet_noofrooms,0)) allarrdomesticchild
   ,sum(decode(yres_resstatus,1,decode(xcac_domestic,1,0,yrgl_number*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end))) defarrchild
   ,sum(decode(yres_resstatus,1,decode(xcac_domestic,1,0,yrgl_number*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end))) defarrchilddayuse
   ,sum(decode(yres_resstatus,0,decode(xcac_domestic,1,0,yrgl_number*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end))) tentarrchild
   ,sum(decode(yres_resstatus,0,decode(xcac_domestic,1,0,yrgl_number*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end))) tentarrchilddayuse
   ,sum(decode(yres_resstatus,1,decode(xcac_domestic,1,yrgl_number*ydet_noofrooms,0))) defarrdomesticchild
   ,sum(decode(yres_resstatus,0,decode(xcac_domestic,1,yrgl_number*ydet_noofrooms,0))) tentarrdomesticchild
   ,sum(decode(xcac_freeofcharge,1,yrgl_number*ydet_noofrooms,0)) allarrfreeofchargechild
   ,sum(decode(yres_resstatus,1,decode(xcac_freeofcharge,1,yrgl_number*ydet_noofrooms,0))) defarrfreeofchargechild
   ,sum(decode(yres_resstatus,0,decode(xcac_freeofcharge,1,yrgl_number*ydet_noofrooms,0))) tentarrfreeofchargechild
from v8_rep_wdat_date_xcma wdat,ydet,yres,yrgl,xcac,ycat

where
    ydet_date=wdat_date 
and yres_exparrtime=wdat_date
and ydet_yres_id=yres_id
and yres_resstatus<>3
and yrgl_ydet_id=ydet_id
and yrgl_xcac_id=xcac_id
and ycat_id=ydet_ycat_id
and ycat_notinavl=0
and ydet_xcma_id=xcma_id
group by wdat_date,yres_resstatus,xcma_id, xcma_id, xcma_xcmm_id
) group by wdat_date,xcma_id,xcma_xcmm_id;


CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA
AS 
SELECT 
V8_REP_REV_FORECAST.YPOS_DATE, 
V8_REP_REV_FORECAST.XCMA_ID, 
V8_REP_REV_FORECAST.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST 
group by 
V8_REP_REV_FORECAST.YPOS_DATE,V8_REP_REV_FORECAST.XCMA_ID,V8_REP_REV_FORECAST.XCMM_ID;



CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STATYPE1
AS 
SELECT 
V8_REP_REV_FORECAST.YPOS_DATE, 
V8_REP_REV_FORECAST.XCMA_ID, 
V8_REP_REV_FORECAST.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST 
where V8_REP_REV_FORECAST.ZDCO_STATS_TYPE in (1) 
group by 
V8_REP_REV_FORECAST.YPOS_DATE,V8_REP_REV_FORECAST.XCMA_ID,V8_REP_REV_FORECAST.XCMM_ID;


CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STATYPE2
AS 
SELECT 
V8_REP_REV_FORECAST.YPOS_DATE, 
V8_REP_REV_FORECAST.XCMA_ID, 
V8_REP_REV_FORECAST.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST 
where V8_REP_REV_FORECAST.ZDCO_STATS_TYPE in (2) 
group by 
V8_REP_REV_FORECAST.YPOS_DATE,V8_REP_REV_FORECAST.XCMA_ID,V8_REP_REV_FORECAST.XCMM_ID;


CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STATYPE3
AS 
SELECT 
V8_REP_REV_FORECAST.YPOS_DATE, 
V8_REP_REV_FORECAST.XCMA_ID,
V8_REP_REV_FORECAST.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST 
where V8_REP_REV_FORECAST.ZDCO_STATS_TYPE in (3) 
group by 
V8_REP_REV_FORECAST.YPOS_DATE,V8_REP_REV_FORECAST.XCMA_ID,V8_REP_REV_FORECAST.XCMM_ID;


CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STATYPE345
AS 
SELECT 
V8_REP_REV_FORECAST.YPOS_DATE, 
V8_REP_REV_FORECAST.XCMA_ID, 
V8_REP_REV_FORECAST.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.YPOS_QUANTITY*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST.YPOS_DT,1,(decode(V8_REP_REV_FORECAST.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST 
where V8_REP_REV_FORECAST.ZDCO_STATS_TYPE in (3,4,5) 
group by 
V8_REP_REV_FORECAST.YPOS_DATE,V8_REP_REV_FORECAST.XCMA_ID,V8_REP_REV_FORECAST.XCMM_ID;


CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_ST345_PRT
AS 
SELECT 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE, 
V8_REP_REV_FORECAST_HUGE.XCMA_ID, 
V8_REP_REV_FORECAST_HUGE.ydet_YCAt_ID ycat_id,
SUM((DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
SUM((DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS, 
SUM(DECODE(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET, 
SUM(DECODE(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET 
FROM V8_REP_REV_FORECAST_HUGE
WHERE V8_REP_REV_FORECAST_HUGE.ZDCO_STATS_TYPE IN (3,4,5) 
GROUP BY 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE,V8_REP_REV_FORECAST_HUGE.XCMA_ID,V8_REP_REV_FORECAST_HUGE.ydet_YCAt_ID;

CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STAT1_CAD
AS
SELECT 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE, 

V8_REP_REV_FORECAST_HUGE.YCAD_ID,
V8_REP_REV_FORECAST_HUGE.XCMA_ID, 
V8_REP_REV_FORECAST_HUGE.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST_HUGE 
where V8_REP_REV_FORECAST_HUGE.ZDCO_STATS_TYPE in (1) 
group by 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE,V8_REP_REV_FORECAST_HUGE.YCAD_ID,V8_REP_REV_FORECAST_HUGE.XCMA_ID,V8_REP_REV_FORECAST_HUGE.XCMM_ID;

CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STAT1_PRT
AS 
SELECT 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE, 
V8_REP_REV_FORECAST_HUGE.XCMA_ID, 
V8_REP_REV_FORECAST_HUGE.ydet_YCAT_ID ycat_id,
SUM((DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
SUM((DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS, 
SUM(DECODE(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET, 
SUM(DECODE(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET 
FROM V8_REP_REV_FORECAST_HUGE
WHERE V8_REP_REV_FORECAST_HUGE.ZDCO_STATS_TYPE IN (1) 
GROUP BY 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE,V8_REP_REV_FORECAST_HUGE.XCMA_ID,V8_REP_REV_FORECAST_HUGE.ydet_YCAt_ID;

CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STAT2_CAD
AS 
SELECT 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE, 

V8_REP_REV_FORECAST_HUGE.YCAD_ID,
V8_REP_REV_FORECAST_HUGE.XCMA_ID, 
V8_REP_REV_FORECAST_HUGE.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST_HUGE 
where V8_REP_REV_FORECAST_HUGE.ZDCO_STATS_TYPE in (2) 
group by 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE,V8_REP_REV_FORECAST_HUGE.YCAD_ID,V8_REP_REV_FORECAST_HUGE.XCMA_ID,V8_REP_REV_FORECAST_HUGE.XCMM_ID;

CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STAT2_PRT
AS 
SELECT 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE, 
V8_REP_REV_FORECAST_HUGE.XCMA_ID, 
V8_REP_REV_FORECAST_HUGE.ydet_YCAt_ID ycat_id,
SUM((DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
SUM((DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS, 
SUM(DECODE(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET, 
SUM(DECODE(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(DECODE(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,NVL((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET 
FROM V8_REP_REV_FORECAST_HUGE
WHERE V8_REP_REV_FORECAST_HUGE.ZDCO_STATS_TYPE IN (2)
GROUP BY 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE,V8_REP_REV_FORECAST_HUGE.XCMA_ID,V8_REP_REV_FORECAST_HUGE.ydet_YCAt_ID;

CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_CAD
AS 
SELECT 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE, 

V8_REP_REV_FORECAST_HUGE.YCAD_ID,
V8_REP_REV_FORECAST_HUGE.XCMA_ID, 
V8_REP_REV_FORECAST_HUGE.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST_HUGE 
group by 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE,V8_REP_REV_FORECAST_HUGE.YCAD_ID,V8_REP_REV_FORECAST_HUGE.XCMA_ID,V8_REP_REV_FORECAST_HUGE.XCMM_ID;

CREATE OR REPLACE VIEW V8_REP_YDET_OCC_WB_XCMA_CAD
AS 
select ycad_id, ydet_xcma_id,ydet_date,sum(defnoofrooms) defnoofrooms, sum(defnoofroomsDayUse) defnoofroomsDayUse, sum(tentnoofrooms) tentnoofrooms,sum(tentnoofroomsDayUse) tentnoofroomsDayUse, sum(tentblockdefresroom) tentblockdefresroom,sum(tentblockdefresroomDayUse) tentblockdefresroomDayUse from
 (
  select
  YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID YCAD_ID,
   ydet_xcma_id,
   ydet_date,
           decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                  , sum(decode(ybst_resstatus,0,decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0),0))
                   -sum(decode(ybst_resstatus,1,decode(yres_resstatus,1,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end,0),0))
          ) defnoofrooms,
          sum(decode(yres_resstatus,1,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
          defnoofroomsDayUse,
          decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  , sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))          
                  ,-sum(decode(ybst_resstatus,0,decode(yres_resstatus,0,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end,0),0)) --substract tentative res only because definitive day use (and non day use) will be substrated by tentblockdefresroom
          ) tentnoofrooms,
          decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,sum(decode(yres_resstatus,0,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))          
                  ,sum(decode(ybst_resstatus,0,decode(yres_resstatus,0,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end,0),0))
                  )
          tentnoofroomsDayUse,
         decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,sum(decode(ybst_resstatus,0,decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0),0))
                  )
          tentblockdefresroom,
           decode(sign(nvl(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,sum(decode(ybst_resstatus,0,decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0),0))
                  )
          tentblockdefresroomDayUse
 from ydet,yres,ybld,yblh,ybst,fideliodate d, ycat
 where
     ydet_yres_id=yres_id(+)
 and ydet_ybld_id=ybld_id(+)
 and ybld_yblh_id=yblh_id(+)
 and yblh_ybst_id=ybst_id(+)
 and yres_resstatus<>3
 --and yres_exparrtime<>yres_expdeptime
 and nvl(ydet_sharenum,0)=0
 and ycat_id = ydet_ycat_id
 and ycat_notinavl=0
 group by YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID,ydet_xcma_id,ydet_date,ydet_sharenum,ybld_cutoffdate,d.WGBS_DATEVALUE
 union all
 select
 YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID YCAD_ID,
   ydet_xcma_id,
   ydet_date,
		 decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then 1 else 0 end,0)))
                  ,decode(max(nvl(ybst_resstatus,0)),0,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then 1 else 0 end,0))),0)
                  )
          defnoofrooms,
          case when max(decode(yres_resstatus,1,yres_expdeptime-yres_exparrtime,0))=0 then 
          decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime=yres_expdeptime then 1 else 0 end,0)))
                  ,decode(max(nvl(ybst_resstatus,0)),0,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then 1 else 0 end,0))),0)
                  ) else 0 end
           defnoofroomsDayUse,
		  decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,decode(sum(yres_resstatus),0,sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then 1 else 0 end,0))),0)
                  ,0                              
                  )
          tentnoofrooms,
          case when max(yres_expdeptime-yres_exparrtime)=0
          then 
          decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,decode(sum(yres_resstatus),0,sum(decode(yres_resstatus,0,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,0,case when yres_exparrtime =yres_expdeptime then 1 else 0 end,0))),0)
                  ,0
                  )
          else 0 end
          tentnoofroomsDayUse,
		  decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,decode(max(nvl(ybst_resstatus,0)),0,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then 1 else 0 end,0))),0)
                  )
          tentblockdefresroom,
           case when max(decode(yres_resstatus,1,yres_expdeptime-yres_exparrtime,0))=0 then 
          decode(sign(nvl(min(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
                  ,0
                  ,decode(max(nvl(ybst_resstatus,0)),0,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then ydet_noofrooms else 0 end,0))/greatest(1,sum(decode(yres_resstatus,1,case when yres_exparrtime =yres_expdeptime then 1 else 0 end,0))),0)
                  ) else 0 end
          tentBlockDefResroomDayUse
 from ydet,yres,ybld,yblh,ybst,fideliodate d, ycat
 where
     ydet_yres_id=yres_id(+)
 and ydet_ybld_id=ybld_id(+)
 and ybld_yblh_id=yblh_id(+)
 and yblh_ybst_id=ybst_id(+)
 and yres_resstatus<>3
 --and yres_exparrtime<>yres_expdeptime
 and nvl(ydet_sharenum,0)<>0
 and ycat_id= ydet_ycat_id
 and ycat_notinavl=0
 group by YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID,ydet_xcma_id,ydet_date,ydet_sharenum,d.WGBS_DATEVALUE
 ) group by ycad_id, ydet_xcma_id,ydet_date;


CREATE OR REPLACE VIEW V8_REP_YDET_ADULT_WB_XCMA_CAD
AS 
SELECT ydet_xcma_id
,ydet_date
,ycad_id
,sum(defadultno) defadultno,
sum(defadultnoDayUse) defadultnoDayUse,
sum(tentadultno) tentadultno,
sum(tentadultnoDayUse) tentadultnoDayUse,
sum(defblocksubstract) defblocksubstract,
sum(tentblocksubstract) tentblocksubstract
FROM
 (
  SELECT
   ydet_xcma_id,
   ydet_date
   ,ycad_id
         ,sum(decode(yres_resstatus,1,case when yres_exparrtime<> yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) defadultno
         ,sum(decode(yres_resstatus,1,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms  else 0 end,0 *ydet_adultno)) defadultnoDayUse
         ,sum(decode(yres_resstatus,0,case when yres_exparrtime<> yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) tentadultno
         ,sum(decode(yres_resstatus,0,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) tentadultnoDayUse
         ,DECODE(SIGN(NVL(MIN(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
            ,0
      ,AVG(ydet_noofrooms)*(AVG(DECODE(ybst_resstatus,1,NVL(ybld_noofadults,0),0)))) defblocksubstract 
         ,DECODE(SIGN(NVL(MIN(ybld_cutoffdate),d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
            ,0
                  ,AVG(ydet_noofrooms)*(AVG(DECODE(ybst_resstatus,0,NVL(ybld_noofadults,0),0)))) tentblocksubstract 
 FROM YDET,YRES,YBLD,YBLH,YBST,fideliodate d,YCAT,YCAD
 WHERE
     ydet_yres_id=yres_id(+)
 AND ydet_ybld_id=ybld_id(+)
 AND ybld_yblh_id=yblh_id(+)
 AND yblh_ybst_id=ybst_id(+)
 AND yres_resstatus<>3
-- AND yres_exparrtime<>yres_expdeptime
 AND ydet_ycat_id=ycat_id
 AND ycat_sum_roomtype_ycad_id=ycad_id
 AND NVL(ydet_sharenum,0)<>0
 GROUP BY ydet_sharenum,ydet_xcma_id,ydet_date,WGBS_DATEVALUE,ycad_id
 UNION ALL
  SELECT
   ydet_xcma_id,
   ydet_date
   ,ycad_id
         ,sum(decode(yres_resstatus,1,case when yres_exparrtime<> yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) defadultno
         ,sum(decode(yres_resstatus,1,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) defadultnoDayUse
         ,sum(decode(yres_resstatus,0,case when yres_exparrtime<> yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) tentadultno
         ,sum(decode(yres_resstatus,0,case when yres_exparrtime= yres_expdeptime then ydet_noofrooms else 0 end *ydet_adultno,0)) tentadultnoDayUse
         ,DECODE(SIGN(NVL(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
            ,0
                  ,SUM(DECODE(NVL(ybst_resstatus,0),1,ydet_noofrooms*NVL(ybld_noofadults,0),0))) defblocksubstract 
         ,DECODE(SIGN(NVL(ybld_cutoffdate,d.WGBS_DATEVALUE-1)-d.WGBS_DATEVALUE),-1
            ,0
                  ,SUM(DECODE(NVL(ybst_resstatus,0),0,ydet_noofrooms*NVL(ybld_noofadults,0),0))) tentblocksubstract 
 FROM YDET,YRES,YBLD,YBLH,YBST,fideliodate d,YCAT,YCAD
 WHERE
     ydet_yres_id=yres_id(+)
 AND ydet_ybld_id=ybld_id(+)
 AND ybld_yblh_id=yblh_id(+)
 AND yblh_ybst_id=ybst_id(+)
 AND yres_resstatus<>3
-- AND yres_exparrtime<>yres_expdeptime
 AND ydet_ycat_id=ycat_id
 AND ycat_sum_roomtype_ycad_id=ycad_id
 AND NVL(ydet_sharenum,0)=0
 GROUP BY ydet_xcma_id,ydet_date,WGBS_DATEVALUE,ybld_cutoffdate,ycad_id
)
GROUP BY ydet_xcma_id,ydet_date,ycad_id;

CREATE OR REPLACE VIEW V8_REP_YBLD_OCC_XCMA_CAD
AS 
SELECT
   yblh_xcma_id,
   ybld_date,
   ycad_id,
   SUM(DECODE(ybst_resstatus,1,DECODE(SIGN(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),0)) defnoofrooms,
   SUM(DECODE(ybst_resstatus,1,DECODE(SIGN(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms*ybld_noofadults),0)) defnoofadults,
   SUM(DECODE(ybst_resstatus,0,DECODE(SIGN(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),0)) tentnoofrooms,
   SUM(DECODE(ybst_resstatus,0,DECODE(SIGN(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms*ybld_noofadults),0)) tentnoofadults,
   sum(decode(ybst_resstatus,1,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms),nvl(ybld_expectednoofrooms,0))) defnoofroomsbookingpos,
   sum(decode(ybst_resstatus,1,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms*nvl(ybld_noofadults,0)),nvl(ybld_expectednoofrooms,0)*nvl(ybld_noofadults,0))) defnoofadultsBookinPos,
   nvl(sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,case when nvl((select sum(YDET.YDET_NOOFROOMS) from ydet,yres where YDET.YDET_YBLD_ID=ybld.ybld_id and YDET.YDET_YRES_ID=yres.yres_id and yres.yres_resstatus=1),0)>=YBLD.YBLD_EXPECTEDNOOFROOMS then 0 else  YBLD.YBLD_EXPECTEDNOOFROOMS-nvl((select sum(YDET.YDET_NOOFROOMS) from ydet,yres where YDET.YDET_YBLD_ID=ybld.ybld_id and YDET.YDET_YRES_ID=yres.yres_id and yres.yres_resstatus=1),0)end))),0) defnoofroomsbookingposavail,
   nvl(sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,case when nvl((select sum(YDET.YDET_NOOFROOMS) from ydet,yres where YDET.YDET_YBLD_ID=ybld.ybld_id and YDET.YDET_YRES_ID=yres.yres_id and yres.yres_resstatus=1),0)>=YBLD.YBLD_EXPECTEDNOOFROOMS then 0 else  YBLD.YBLD_EXPECTEDNOOFROOMS-nvl((select sum(YDET.YDET_NOOFROOMS) from ydet,yres where YDET.YDET_YBLD_ID=ybld.ybld_id and YDET.YDET_YRES_ID=yres.yres_id and yres.yres_resstatus=1),0)end * YBLD.YBLD_NOOFADULTS ))),0) defnoofadultsbookingposavail,
   sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,ybld_actualnoofrooms-nvl(ybld_expectednoofrooms,0)),0)) tentnoofroomsbookingpos,
   sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,(ybld_actualnoofrooms-nvl(ybld_expectednoofrooms,0))*nvl(ybld_noofadults,0)),0)) tentnoofadultsBookingPos,
   nvl(sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,case when nvl((select sum(YDET.YDET_NOOFROOMS) from ydet,yres where YDET.YDET_YBLD_ID=ybld.ybld_id and YDET.YDET_YRES_ID=yres.yres_id and yres.yres_resstatus=1),0)>=YBLD.YBLD_EXPECTEDNOOFROOMS then YBLD.YBLD_ACTUALNOOFROOMS-nvl((select sum(YDET.YDET_NOOFROOMS) from ydet,yres where YDET.YDET_YBLD_ID=ybld.ybld_id and YDET.YDET_YRES_ID=yres.yres_id and yres.yres_resstatus=1),0) else YBLD.YBLD_ACTUALNOOFROOMS-YBLD.YBLD_EXPECTEDNOOFROOMS  end))),0) tentnoofroomsbookingposavail,
   nvl(sum(decode(ybst_resstatus,0,decode(sign(ybld_cutoffdate-d.WGBS_DATEVALUE),-1,0,case when nvl((select sum(YDET.YDET_NOOFROOMS) from ydet,yres where YDET.YDET_YBLD_ID=ybld.ybld_id and YDET.YDET_YRES_ID=yres.yres_id and yres.yres_resstatus=1),0)>=YBLD.YBLD_EXPECTEDNOOFROOMS then YBLD.YBLD_ACTUALNOOFROOMS-nvl((select sum(YDET.YDET_NOOFROOMS) from ydet,yres where YDET.YDET_YBLD_ID=ybld.ybld_id and YDET.YDET_YRES_ID=yres.yres_id and yres.yres_resstatus=1),0) else YBLD.YBLD_ACTUALNOOFROOMS-YBLD.YBLD_EXPECTEDNOOFROOMS  end * YBLD.YBLD_NOOFADULTS))),0) tentnoofadultsbookingposavail
FROM YBLD,YBLH,YBST,fideliodate d,YCAT,YCAD
WHERE
    ybld_yblh_id=yblh_id
AND YBLH_YBST_ID=ybst_id
AND YBST_RESSTATUS<>3
AND ybld_ycat_id=ycat_id
AND ycat_sum_roomtype_ycad_id=ycad_id
GROUP BY yblh_xcma_id,ybld_date,ycad_id;


CREATE OR REPLACE VIEW V8_REP_HS_ARR_ALLCHI_XCMA_CAD
AS
select wdat_date
    ,ycad_id
    ,xcma_id XCMA_ID
    ,xcma_xcmm_id xcmm_id
    ,nvl(sum(allarrchild),0) allarrchild
    ,nvl(sum(defarrchild),0) defarrchild
    ,nvl(sum(defarrchilddayuse),0) defarrchilddayuse
    ,nvl(sum(tentarrchild),0) tentarrchild 
    ,nvl(sum(tentarrchilddayuse),0) tentarrchilddayuse
   ,nvl(sum(allarrdomesticchild),0) allarrdomesticchild
   ,nvl(sum(defarrdomesticchild),0) defarrdomesticchild
   ,nvl(sum(tentarrdomesticchild),0) tentarrdomesticchild           
   ,nvl(sum(allarrfreeofchargechild),0) allarrfreeofchargechild
   ,nvl(sum(defarrfreeofchargechild),0) defarrfreeofchargechild
   ,nvl(sum(tentarrfreeofchargechild),0) tentarrfreeofchargechild           
from (
select 
   wdat_date
   ,ycad_id
   ,xcma_id
   ,xcma_xcmm_id
   ,sum(yrgl_number*ydet_noofrooms) allarrchild
   ,sum(decode(xcac_domestic,1,yrgl_number*ydet_noofrooms,0)) allarrdomesticchild
   ,sum(decode(yres_resstatus,1,decode(xcac_domestic,1,0,yrgl_number*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end))) defarrchild
   ,sum(decode(yres_resstatus,1,decode(xcac_domestic,1,0,yrgl_number*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end))) defarrchilddayuse
   ,sum(decode(yres_resstatus,0,decode(xcac_domestic,1,0,yrgl_number*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end))) tentarrchild
   ,sum(decode(yres_resstatus,0,decode(xcac_domestic,1,0,yrgl_number*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end))) tentarrchilddayuse
   ,sum(decode(yres_resstatus,1,decode(xcac_domestic,1,yrgl_number*ydet_noofrooms,0))) defarrdomesticchild
   ,sum(decode(yres_resstatus,0,decode(xcac_domestic,1,yrgl_number*ydet_noofrooms,0))) tentarrdomesticchild
   ,sum(decode(xcac_freeofcharge,1,yrgl_number*ydet_noofrooms,0)) allarrfreeofchargechild
   ,sum(decode(yres_resstatus,1,decode(xcac_freeofcharge,1,yrgl_number*ydet_noofrooms,0))) defarrfreeofchargechild
   ,sum(decode(yres_resstatus,0,decode(xcac_freeofcharge,1,yrgl_number*ydet_noofrooms,0))) tentarrfreeofchargechild
from v8_rep_wdat_date_xcma_cad wdat,ydet,yres,yrgl,xcac,ycat
where
    ydet_date=wdat_date 
and yres_exparrtime=wdat_date
and ydet_yres_id=yres_id
and yres_resstatus<>3
and yrgl_ydet_id=ydet_id
and yrgl_xcac_id=xcac_id
and ycat_id=ydet_ycat_id
and ycat_notinavl=0
and ydet_xcma_id=xcma_id
group by wdat_date,ycad_id,yres_resstatus,xcma_id, xcma_id, xcma_xcmm_id
) group by wdat_date,ycad_id,xcma_id,xcma_xcmm_id;


CREATE OR REPLACE VIEW V8_REP_HS_ARR_ALLADULT_XCMA
AS 
SELECT wdat_date
    ,xcma_id xcma_id
    ,xcma_xcmm_id xcmm_id
   ,sum(allexpadult) allexpadult,sum(defexpadult) defexpadult,sum(tentexpadult) tentexpadult  
   ,sum(allexpadultDayUse) allexpadultDayUse,sum(defexpadultDayUse) defexpadultDayUse,sum(tentexpadultDayUse) tentexpadultDayUse  
from (
SELECT 
   wdat_date
   ,xcma_id
   ,xcma_xcmm_id
   ,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end) allexpadult
   ,decode(yres_resstatus,1,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) defexpadult
   ,decode(yres_resstatus,0,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) tentexpadult
   ,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end) allexpadultDayUse
   ,decode(yres_resstatus,1,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) defexpadultDayUse
   ,decode(yres_resstatus,0,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) tentexpadultDayUse
FROM V8_REP_WDAT_DATE_XCMA WDAT,YDET,YRES,YCAT
WHERE
    ydet_date=wdat_date 
AND yres_exparrtime=wdat_date
AND ydet_yres_id=yres_id
AND ydet_ycat_id=ycat_id
AND ycat_notinavl=0
AND yres_resstatus<>3
AND ydet_xcma_id=xcma_id
GROUP BY wdat_date,yres_resstatus,xcma_id, xcma_xcmm_id
) GROUP BY wdat_date,xcma_id, xcma_xcmm_id;


CREATE OR REPLACE VIEW V8_REP_HS_ARR_ALLROOM_XCMA
AS 
SELECT wdat_date
      ,xcma_id xcma_ID
      ,xcma_xcmm_id xcmm_id
      ,sum(allexproom) allexproom,sum(defexproom) defexproom,sum(tentexproom) tentexproom  
      ,sum(allexproomDayUse) allexproomDayUse,sum(defexproomDayUse) defexproomDayUse,sum(tentexproomDayUse) tentexproomDayUse  
from (
SELECT 
   wdat_date
   ,xcma_id
   ,xcma_xcmm_id
   ,decode(nvl(ydet_sharenum,0),0,sum(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)
                                 ,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) allexproom
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),1,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end),0)) defexproom
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),0,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end),0)) tentexproom
   ,
    decode(nvl(ydet_sharenum,0),0,sum(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)
                                 ,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) allexproomDayUse
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,1,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),1,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end),0)) defexproomDayUse
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,0,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),0,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end),0)) tentexproomDayUse
FROM V8_REP_WDAT_DATE_XCMA WDAT,YDET yd,YRES y,YCAT
WHERE
    ydet_date=wdat_date 
AND yres_exparrtime=wdat_date
AND ydet_yres_id=yres_id
AND ydet_ycat_id=ycat_id
AND ycat_notinavl=0
AND yres_resstatus<>3
AND ydet_xcma_id=xcma_id
AND (NVL(ydet_sharenum,0)=0
     OR
  NOT EXISTS (SELECT d.ydet_sharenum 
                        FROM YDET d,YRES r 
         WHERE d.ydet_yres_id=r.yres_id
        AND d.ydet_id<>yd.ydet_id 
        AND (y.yres_exparrtime<>r.yres_exparrtime)
        AND d.ydet_sharenum=yd.ydet_sharenum
         )
 )
GROUP BY wdat_date,ydet_sharenum,xcma_id, xcma_xcmm_id
) GROUP BY wdat_date,xcma_id, xcma_xcmm_id;

CREATE OR REPLACE VIEW V8_REP_HS_DEP_ALLADULT_XCMA
AS
select wdat_date
    ,xcma_id
    , xcmm_id
   ,sum(alldepadult) alldepadult,sum(defdepadult) defdepadult,sum(tentdepadult) tentdepadult  
   ,sum(alldepadultDayUse) alldepadultDayUse,sum(defdepadultDayUse) defdepadultDayUse,sum(tentdepadultDayUse) tentdepadultDayUse  
from (
select 
   wdat_date
   ,xcma_ID xcma_id
   ,xcma_xcmm_id xcmm_id
   ,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end) alldepadult
   ,decode(yres_resstatus,1,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) defdepadult
   ,decode(yres_resstatus,0,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) tentdepadult
   ,
    sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end) alldepadultDayUse
   ,decode(yres_resstatus,1,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) defdepadultDayUse
   ,decode(yres_resstatus,0,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) tentdepadultDayUse
from v8_rep_wdat_date_xcma wdat,ydet,yres,ycat
where
ydet_id=yres_last_ydet_id
and yres_expdeptime=wdat_date 	
and yres_resstatus<>3
and ycat_id=ydet_ycat_id
and ydet_xcma_id=xcma_id
group by wdat_date,yres_resstatus,xcma_ID, xcma_xcmm_id
) group by wdat_date,xcma_id, xcmm_id;


CREATE OR REPLACE VIEW V8_REP_HS_DEP_ALLROOM_XCMA
AS 
select wdat_date
    ,xcma_id
    ,xcmm_id
   ,sum(alldeproom) alldeproom,sum(defdeproom) defdeproom ,sum(tentdeproom) tentdeproom  
   ,sum(alldeproomDayUse) alldeproomDayUse,sum(defdeproomDayUse) defdeproomDayUse,sum(tentdeproomDayUse) tentdeproomDayUse  
from (
select 
   wdat_date
   ,xcma_ID xcma_id
   ,xcma_xcmm_id xcmm_id
   ,ydet_sharenum
   ,decode(nvl(ydet_sharenum,0),0,sum(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)
                                 ,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) alldeproom
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),1,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end),0)) defdeproom
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),0,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end),0)) tentdeproom
   ,
    decode(nvl(ydet_sharenum,0),0,sum(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)
                                 ,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) alldeproomDayUse
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,1,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),1,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end),0)) defdeproomDayUse
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,0,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),0,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end),0)) tentdeproomDayUse
from v8_rep_WDAT_DATE_XCMA wdat,ydet yd,yres y,ycat
where
ydet_id=yres_last_ydet_id
and yres_expdeptime=wdat_date 	
and yres_resstatus<>3
and (nvl(ydet_sharenum,0)= 0
     or
	 not exists (select d.ydet_sharenum 
	                       from ydet d,yres r 
				where d.ydet_yres_id=r.yres_id
							 and d.ydet_id<>yd.ydet_id 
							 and y.yres_expdeptime<>r.yres_expdeptime 
							 and d.ydet_sharenum=yd.ydet_sharenum
				)
	)
and ycat_id=ydet_ycat_id
and ydet_xcma_id=xcma_id
group by wdat_date,ydet_sharenum,xcma_ID, xcma_xcmm_id)
group by wdat_date,xcma_id, xcmm_id;


CREATE OR REPLACE VIEW V8_REP_HS_ARR_DEP_COMB_SM_XCMA
AS 
select wdat_date
       ,xcma_id
       ,XCMM_ID XCMM_id
       ,sum(decode(vtype,1,num,0)) arrexproom
       ,sum(decode(vtype,2,num,0)) arrexpadult
       ,sum(decode(vtype,3,num,0)) depexproom
       ,sum(decode(vtype,4,num,0)) depexpadult
       ,sum(decode(vtype,1,numdu,0)) arrexproomdayuse
       ,sum(decode(vtype,2,numdu,0)) arrexpadultdayuse
       ,sum(decode(vtype,3,numdu,0)) depexproomdayuse
       ,sum(decode(vtype,4,numdu,0)) depexpadultdayuse
from (
select wdat_date,1 vtype,xcma_id,xcmm_id,allexproom num,allexproomdayuse numdu from v8_rep_hs_arr_allroom_xcma 
union
select wdat_date,2 vtype,xcma_id,xcmm_id,allexpadult num,allexpadultdayuse numdu from v8_rep_hs_arr_alladult_xcma 
union
select wdat_date,3 vtype,xcma_id,xcmm_id,alldeproom num,alldeproomdayuse numdu from v8_rep_hs_dep_allroom_xcma
union 
select wdat_date,4 vtype,xcma_id,xcmm_id,alldepadult num,alldepadultdayuse numdu from v8_rep_hs_dep_alladult_xcma
union 
select wdat_date,0 vtype,xcma_id,xcma_xcmm_id xcmm_id, 0 num,0 numdu from wdat,xcma
)
group by wdat_date,xcma_id, xcmm_id;

CREATE OR REPLACE VIEW V8_REP_HS_ARR_ALLADL_XCMA_CAD
AS 
SELECT wdat_date
    ,ycad_id
    ,xcma_id xcma_id
    ,xcma_xcmm_id xcmm_id
   ,sum(allexpadult) allexpadult,sum(defexpadult) defexpadult,sum(tentexpadult) tentexpadult  
   ,sum(allexpadultDayUse) allexpadultDayUse,sum(defexpadultDayUse) defexpadultDayUse,sum(tentexpadultDayUse) tentexpadultDayUse  
from (
SELECT 
   wdat_date
   ,ycad_id
   ,xcma_id
   ,xcma_xcmm_id
   ,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end) allexpadult
   ,decode(yres_resstatus,1,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) defexpadult
   ,decode(yres_resstatus,0,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) tentexpadult
   ,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end) allexpadultDayUse
   ,decode(yres_resstatus,1,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) defexpadultDayUse
   ,decode(yres_resstatus,0,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) tentexpadultDayUse
FROM V8_REP_WDAT_DATE_XCMA_CAD WDAT,YDET,YRES,YCAT
WHERE
    ydet_date=wdat_date 
AND yres_exparrtime=wdat_date
AND ydet_yres_id=yres_id
AND ydet_ycat_id=ycat_id
AND ycat_notinavl=0
AND yres_resstatus<>3
AND ydet_xcma_id=xcma_id
GROUP BY wdat_date,ycad_id,yres_resstatus,xcma_id, xcma_xcmm_id
) GROUP BY wdat_date,ycad_id,xcma_id, xcma_xcmm_id;


CREATE OR REPLACE VIEW V8_REP_HS_ARR_ALLRMS_XCMA_CAD
AS 
SELECT wdat_date
      ,ycad_id
      ,xcma_id xcma_ID
      ,xcma_xcmm_id xcmm_id
      ,sum(allexproom) allexproom,sum(defexproom) defexproom,sum(tentexproom) tentexproom  
      ,sum(allexproomDayUse) allexproomDayUse,sum(defexproomDayUse) defexproomDayUse,sum(tentexproomDayUse) tentexproomDayUse  
from (
SELECT 
   wdat_date
   ,ycad_id
   ,xcma_id
   ,xcma_xcmm_id
   ,decode(nvl(ydet_sharenum,0),0,sum(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)
                                 ,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) allexproom
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),1,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end),0)) defexproom
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),0,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end),0)) tentexproom
   ,
    decode(nvl(ydet_sharenum,0),0,sum(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)
                                 ,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) allexproomDayUse
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,1,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),1,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end),0)) defexproomDayUse
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,0,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),0,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end),0)) tentexproomDayUse
FROM V8_REP_WDAT_DATE_XCMA_cad WDAT,YDET yd,YRES y,YCAT
WHERE
    ydet_date=wdat_date 
AND yres_exparrtime=wdat_date
AND ydet_yres_id=yres_id
AND ydet_ycat_id=ycat_id
AND ycat_notinavl=0
AND yres_resstatus<>3
AND ydet_xcma_id=xcma_id
AND (NVL(ydet_sharenum,0)=0
     OR
  NOT EXISTS (SELECT d.ydet_sharenum 
                        FROM YDET d,YRES r 
         WHERE d.ydet_yres_id=r.yres_id
        AND d.ydet_id<>yd.ydet_id 
        AND (y.yres_exparrtime<>r.yres_exparrtime)
        AND d.ydet_sharenum=yd.ydet_sharenum
         )
 )
GROUP BY wdat_date,ycad_id,ydet_sharenum,xcma_id, xcma_xcmm_id
) GROUP BY wdat_date,ycad_id,xcma_id, xcma_xcmm_id;


CREATE OR REPLACE VIEW V8_REP_HS_DEP_ALLADL_XCMA_CAD
AS
select wdat_date
    ,ycad_id
    ,xcma_id
    , xcmm_id
   ,sum(alldepadult) alldepadult,sum(defdepadult) defdepadult,sum(tentdepadult) tentdepadult  
   ,sum(alldepadultDayUse) alldepadultDayUse,sum(defdepadultDayUse) defdepadultDayUse,sum(tentdepadultDayUse) tentdepadultDayUse  
from (
select 
   wdat_date
   ,ycad_id
   ,xcma_ID xcma_id
   ,xcma_xcmm_id xcmm_id
   ,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end) alldepadult
   ,decode(yres_resstatus,1,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) defdepadult
   ,decode(yres_resstatus,0,sum(ydet_adultno*case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) tentdepadult
   ,
    sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end) alldepadultDayUse
   ,decode(yres_resstatus,1,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) defdepadultDayUse
   ,decode(yres_resstatus,0,sum(ydet_adultno*case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) tentdepadultDayUse
from v8_rep_wdat_date_xcma_cad wdat,ydet,yres,ycat
where
ydet_id=yres_last_ydet_id
and yres_expdeptime=wdat_date 	
and yres_resstatus<>3
and ycat_id=ydet_ycat_id
and ydet_xcma_id=xcma_id
group by wdat_date,ycad_id,yres_resstatus,xcma_ID, xcma_xcmm_id
) group by wdat_date,ycad_id,xcma_id, xcmm_id;


CREATE OR REPLACE VIEW V8_REP_HS_DEP_ALLRMS_XCMA_CAD
AS
select wdat_date
    ,ycad_id
    ,xcma_id
    ,xcmm_id
   ,sum(alldeproom) alldeproom,sum(defdeproom) defdeproom ,sum(tentdeproom) tentdeproom  
   ,sum(alldeproomDayUse) alldeproomDayUse,sum(defdeproomDayUse) defdeproomDayUse,sum(tentdeproomDayUse) tentdeproomDayUse  
from (
select 
   wdat_date
   ,ycad_id
   ,xcma_ID xcma_id
   ,xcma_xcmm_id xcmm_id
   ,ydet_sharenum
   ,decode(nvl(ydet_sharenum,0),0,sum(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)
                                 ,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end)) alldeproom
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,1,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),1,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end),0)) defdeproom
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,0,case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),0,avg(case when yres_exparrtime<>yres_expdeptime then ydet_noofrooms else 0 end),0)) tentdeproom
   ,
    decode(nvl(ydet_sharenum,0),0,sum(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)
                                 ,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end)) alldeproomDayUse
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,1,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),1,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end),0)) defdeproomDayUse
   ,decode(nvl(ydet_sharenum,0),0,sum(decode(yres_resstatus,0,case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end,0))
                                 ,decode(max(yres_resstatus),0,avg(case when yres_exparrtime=yres_expdeptime then ydet_noofrooms else 0 end),0)) tentdeproomDayUse
from v8_rep_WDAT_DATE_XCMA_cad wdat,ydet yd,yres y,ycat
where
ydet_id=yres_last_ydet_id
and yres_expdeptime=wdat_date 	
and yres_resstatus<>3
and (nvl(ydet_sharenum,0)= 0
     or
	 not exists (select d.ydet_sharenum 
	                       from ydet d,yres r 
				where d.ydet_yres_id=r.yres_id
							 and d.ydet_id<>yd.ydet_id 
							 and y.yres_expdeptime<>r.yres_expdeptime 
							 and d.ydet_sharenum=yd.ydet_sharenum
				)
	)
and ycat_id=ydet_ycat_id
and ydet_xcma_id=xcma_id
group by wdat_date,ycad_id,ydet_sharenum,xcma_ID, xcma_xcmm_id)
group by wdat_date,ycad_id,xcma_id, xcmm_id;


CREATE OR REPLACE VIEW V8_REP_ARR_DEP_COMB_XCMA_CAD
AS 
select wdat_date
       ,ycad_id
       ,xcma_id
       ,XCMM_ID XCMM_id
       ,sum(decode(vtype,1,num,0)) arrexproom
       ,sum(decode(vtype,2,num,0)) arrexpadult
       ,sum(decode(vtype,3,num,0)) depexproom
       ,sum(decode(vtype,4,num,0)) depexpadult
       ,sum(decode(vtype,1,numdu,0)) arrexproomdayuse
       ,sum(decode(vtype,2,numdu,0)) arrexpadultdayuse
       ,sum(decode(vtype,3,numdu,0)) depexproomdayuse
       ,sum(decode(vtype,4,numdu,0)) depexpadultdayuse
from (
select wdat_date,1 vtype,ycad_id,xcma_id,xcmm_id,allexproom num,allexproomdayuse numdu from V8_REP_HS_ARR_ALLRMS_XCMA_CAD 
union
select wdat_date,2 vtype,ycad_id,xcma_id,xcmm_id,allexpadult num,allexpadultdayuse numdu from V8_REP_HS_ARR_ALLADL_XCMA_CAD 
union
select wdat_date,3 vtype,ycad_id,xcma_id,xcmm_id,alldeproom num,alldeproomdayuse numdu from V8_REP_HS_DEP_ALLRMS_XCMA_CAD
union 
select wdat_date,4 vtype,ycad_id,xcma_id,xcmm_id,alldepadult num,alldepadultdayuse numdu from V8_REP_HS_DEP_ALLADL_XCMA_CAD
union 
select wdat_date,0 vtype,ycad_id,xcma_id,xcma_xcmm_id xcmm_id, 0 num,0 numdu from v8_rep_wdat_date_xcma_cad wdat
)
group by wdat_date,ycad_id,xcma_id, xcmm_id;


CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_STAT3_CAD
AS 
SELECT 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE, 
V8_REP_REV_FORECAST_HUGE.XCMA_ID,
V8_REP_REV_FORECAST_HUGE.XCMM_ID,
V8_REP_REV_FORECAST_HUGE.YCAD_ID,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST_HUGE 
where V8_REP_REV_FORECAST_HUGE.ZDCO_STATS_TYPE in (3) 
group by 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE,V8_REP_REV_FORECAST_HUGE.XCMA_ID,V8_REP_REV_FORECAST_HUGE.XCMM_ID,V8_REP_REV_FORECAST_HUGE.YCAD_ID;


CREATE OR REPLACE VIEW V8_REP_YPOS_FC_XCMA_ST345_CAD
AS 
SELECT 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE, 
V8_REP_REV_FORECAST_HUGE.YCAD_ID,
V8_REP_REV_FORECAST_HUGE.XCMA_ID, 
V8_REP_REV_FORECAST_HUGE.XCMM_ID,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS, 
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((   ( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )    *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0))) DEF_REV_GROSS_BOOKINGPOS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS,
sum((decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((  V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0)))) TENT_REV_GROSS_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),1,0,2,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),3,0,4,nvl((( case when nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) > nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) then nvl(V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY,0) else nvl(V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS,0) end  )  *V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),5,0)),0)) DEF_REV_NET_BOOKINGPOS, 
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.YPOS_QUANTITY*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET,
sum(decode(V8_REP_REV_FORECAST_HUGE.YPOS_DT,1,(decode(V8_REP_REV_FORECAST_HUGE.TYPENUM,0,0,1,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),2,0,3,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0),4,0,5,nvl((V8_REP_REV_FORECAST_HUGE.QUANTITY_BOOKINGPOS*V8_REP_REV_FORECAST_HUGE.YPOS_UNITPRICE),0))),0)) TENT_REV_NET_BOOKINGPOS  
FROM V8_REP_REV_FORECAST_HUGE 
where V8_REP_REV_FORECAST_HUGE.ZDCO_STATS_TYPE in (3,4,5) 
group by 
V8_REP_REV_FORECAST_HUGE.YPOS_DATE,V8_REP_REV_FORECAST_HUGE.YCAD_ID,V8_REP_REV_FORECAST_HUGE.XCMA_ID,V8_REP_REV_FORECAST_HUGE.XCMM_ID;

CREATE OR REPLACE VIEW V8_REP_REV_HISTFOR_HUGE_XCMA
AS
select
WDAT_DATE    WDAT_DATE,
WDAT_DATE2    WDAT_DATE2,
WDAT_DATE3    WDAT_DATE3,
MONTHYEAR    MONTHYEAR,
FUTURE    FUTURE,
XCMA_ID    XCMA_ID,
XCMM_ID     XCMM_ID,
OCC_ROOMS_DEF    OCC_ROOMS_DEF,
OCC_ROOMS_DEF_BOOKINGPOS    OCC_ROOMS_DEF_BOOKINGPOS,
OCC_ROOMS_TENT    OCC_ROOMS_TENT,
OCC_ROOMS_TENT_BOOKINGPOS    OCC_ROOMS_TENT_BOOKINGPOS,
ARR_ROOMS_DEF_TENT    ARR_ROOMS_DEF_TENT,
ARR_ROOMS_DEF    ARR_ROOMS_DEF,
DEP_ROOMS_DEF_TENT    DEP_ROOMS_DEF_TENT,
DEP_ROOMS_DEF    DEP_ROOMS_DEF,
OCC_ADULTS_DEF    OCC_ADULTS_DEF,
OCC_ADULTS_DEF_BOOKINGPOS    OCC_ADULTS_DEF_BOOKINGPOS,
OCC_ADULTS_TENT    OCC_ADULTS_TENT,
OCC_ADULTS_TENT_BOOKINGPOS    OCC_ADULTS_TENT_BOOKINGPOS,
BUD_NOOFADULTS    BUD_NOOFADULTS,
OCC_CHILDS_DEF    OCC_CHILDS_DEF,
OCC_CHILDS_TENT    OCC_CHILDS_TENT,
DEF_ARR_ADULTS    DEF_ARR_ADULTS,
TENT_ARR_ADULTS    TENT_ARR_ADULTS,
DEF_ARR_KIDS    DEF_ARR_KIDS,
TENT_ARR_KIDS    TENT_ARR_KIDS,
BUD_REV_GROSS    BUD_REV_GROSS,
BUD_REV_NET    BUD_REV_NET,
DEF_ROOM_REV_GROSS    DEF_ROOM_REV_GROSS,
DEF_RM_REV_GROSS_BOOKINGPOS    DEF_RM_REV_GROSS_BOOKINGPOS,
TENT_ROOM_REV_GROSS    TENT_ROOM_REV_GROSS,
TENT_RM_REV_GROSS_BOOKINGPOS    TENT_RM_REV_GROSS_BOOKINGPOS,
DEF_ROOM_REV_NET    DEF_ROOM_REV_NET,
DEF_RM_REV_NET_BOOKINGPOS    DEF_RM_REV_NET_BOOKINGPOS,
TENT_ROOM_REV_NET    TENT_ROOM_REV_NET,
TENT_RM_REV_NET_BOOKINGPOS    TENT_RM_REV_NET_BOOKINGPOS,
DEF_FB_REV_GROSS    DEF_FB_REV_GROSS,
DEF_FB_REV_GROSS_BOOKINGPOS    DEF_FB_REV_GROSS_BOOKINGPOS,
TENT_FB_REV_GROSS    TENT_FB_REV_GROSS,
TENT_FB_REV_GROSS_BOOKINGPOS    TENT_FB_REV_GROSS_BOOKINGPOS,
DEF_FB_REV_NET    DEF_FB_REV_NET,
DEF_FB_REV_NET_BOOKINGPOS    DEF_FB_REV_NET_BOOKINGPOS,
TENT_FB_REV_NET    TENT_FB_REV_NET,
TENT_FB_REV_NET_BOOKINGPOS    TENT_FB_REV_NET_BOOKINGPOS,
DEF_OTHER_REV_GROSS    DEF_OTHER_REV_GROSS,
DEF_OTH_REV_GROSS_BOOKPOS    DEF_OTH_REV_GROSS_BOOKPOS,
TENT_OTHER_REV_GROSS    TENT_OTHER_REV_GROSS,
TENT_OTH_REV_GROSS_BOOKPOS    TENT_OTH_REV_GROSS_BOOKPOS,
DEF_OTHER_REV_NET    DEF_OTHER_REV_NET,
DEF_OTH_REV_NET_BOOKPOS    DEF_OTH_REV_NET_BOOKPOS,
TENT_OTHER_REV_NET    TENT_OTHER_REV_NET,
TENT_OTH_REV_NET_BOOKPOS    TENT_OTH_REV_NET_BOOKPOS,
DEF_REV_GROSS                           DEF_REV_GROSS,
DEF_REV_GROSS_BOOKINGPOS       DEF_REV_GROSS_BOOKINGPOS,
TENT_REV_GROSS                          TENT_REV_GROSS,
TENT_REV_GROSS_BOOKINGPOS       TENT_REV_GROSS_BOOKINGPOS,
DEF_REV_NET                                 DEF_REV_NET,
DEF_REV_NET_BOOKINGPOS              DEF_REV_NET_BOOKINGPOS,
TENT_REV_NET                                TENT_REV_NET,
TENT_REV_NET_BOOKINGPOS             TENT_REV_NET_BOOKINGPOS,
DAYUSE_RMS_DEF     DAYUSE_RMS_DEF, 
DAYUSE_RMS_TENT     DAYUSE_RMS_TENT, 
ARR_DAYUSE_RMS_DEF_TENT     ARR_DAYUSE_RMS_DEF_TENT, 
ARR_DAYUSE_RMS_DEF    ARR_DAYUSE_RMS_DEF,
DEP_DAYUSE_RMS_DEF_TENT    DEP_DAYUSE_RMS_DEF_TENT,
DEP_DAYUSE_RMS_DEF    DEP_DAYUSE_RMS_DEF,
DAYUSE_ADLT_DEF     DAYUSE_ADLT_DEF, 
DAYUSE_ADLT_TENT    DAYUSE_ADLT_TENT,
DAYUSE_CHILDS_DEF    DAYUSE_CHILDS_DEF,
DAYUSE_CHILDS_TENT    DAYUSE_CHILDS_TENT,
BLOCK_ALL_DEF    BLOCK_ALL_DEF,
BLOCK_ALL_TENT    BLOCK_ALL_TENT,
BLOCK_NOT_PICKUP_DEF    BLOCK_NOT_PICKUP_DEF,
BLOCK_NOT_PICKUP_TENT    BLOCK_NOT_PICKUP_TENT,
BLOCK_PICKUP_DEF    BLOCK_PICKUP_DEF,
BLOCK_PICKUP_TENT    BLOCK_PICKUP_TENT
from
(
select 
WDAT.WDAT_DATE WDAT_DATE, 
WDAT.WDAT_DATE WDAT_DATE2,
WDAT.WDAT_DATE WDAT_DATE3,
TO_CHAR(WDAT.WDAT_DATE,'yyyy_mm') MonthYear, 
WDAT.FUTURE FUTURE,
WDAT.XCMA_ID XCMA_ID,
WDAT.XCMA_XCMM_ID XCMM_ID,
NVL(SUM(DECODE(shis.SHIS_YRES_RESSTATUS,3,0,decode(shis.SHIS_DEP_ID,1,0,shis.SHIS_YDET_NOOFROOMS))),0) OCC_ROOMS_DEF, 
NVL(SUM(DECODE(shis.SHIS_YRES_RESSTATUS,3,0,decode(shis.SHIS_DEP_ID,1,0,shis.SHIS_YDET_NOOFROOMS))),0) OCC_ROOMS_DEF_BOOKINGPOS,
0 OCC_ROOMS_TENT,
0 OCC_ROOMS_TENT_BOOKINGPOS,
NVL(SUM(DECODE(shis.SHIS_YRES_RESSTATUS,3,0,decode(shis.SHIS_ARR_ID,1,shis.SHIS_YDET_NOOFROOMS,0))),0) ARR_ROOMS_DEF_TENT,
NVL(SUM(DECODE(shis.SHIS_YRES_RESSTATUS,1,decode(shis.SHIS_ARR_ID,1,shis.SHIS_YDET_NOOFROOMS,0))),0) ARR_ROOMS_DEF,  
NVL(SUM(DECODE(shis.SHIS_YRES_RESSTATUS,3,0,decode(shis.SHIS_DEP_ID,1,shis.SHIS_YDET_NOOFROOMS,0))),0) DEP_ROOMS_DEF_TENT,
NVL(SUM(DECODE(shis.SHIS_YRES_RESSTATUS ,1,decode(shis.SHIS_DEP_ID,1,shis.SHIS_YDET_NOOFROOMS,0))),0) DEP_ROOMS_DEF, 
NVL(SUM(DECODE(shis.SHIS_YRES_RESSTATUS,3,0,decode(shis.SHIS_DEP_ID,1,0,shis.SHIS_YDET_ADULTNO))),0) OCC_ADULTS_DEF, 
NVL(SUM(DECODE(shis.SHIS_YRES_RESSTATUS,3,0,decode(shis.SHIS_DEP_ID,1,0,shis.SHIS_YDET_ADULTNO))),0) OCC_ADULTS_DEF_BOOKINGPOS,
0 OCC_ADULTS_TENT,
0 OCC_ADULTS_TENT_BOOKINGPOS,
0 BUD_NOOFADULTS,
NVL(SUM(DECODE(SHIS.SHIS_YRES_RESSTATUS,3,0,DECODE(SHIS.SHIS_DEP_ID,1,0,SHIS.SHIS_TOTALYRGL_NUMBER ))),0) OCC_CHILDS_DEF, 
0 OCC_CHILDS_TENT, 
0 DEF_ARR_ADULTS,
0 TENT_ARR_ADULTS,
0 DEF_ARR_KIDS,
0 TENT_ARR_KIDS,
0 BUD_REV_GROSS,
0 BUD_REV_NET,
NVL(SUM(shis.SHIS_GROSSROOMREV),0) DEF_ROOM_REV_GROSS,
NVL(SUM(shis.SHIS_GROSSROOMREV),0) DEF_RM_REV_GROSS_BOOKINGPOS,
0 TENT_ROOM_REV_GROSS,
0 TENT_RM_REV_GROSS_BOOKINGPOS,
NVL(SUM(SHIS.SHIS_NETROOMREV),0) DEF_ROOM_REV_NET,
NVL(SUM(SHIS.SHIS_NETROOMREV),0) DEF_RM_REV_NET_BOOKINGPOS,
0 TENT_ROOM_REV_NET,
0 TENT_RM_REV_NET_BOOKINGPOS,
NVL(SUM(SHIS.SHIS_GROSSFBREV),0) DEF_FB_REV_GROSS,
NVL(SUM(SHIS.SHIS_GROSSFBREV),0) DEF_FB_REV_GROSS_BOOKINGPOS,
0 TENT_FB_REV_GROSS,
0 TENT_FB_REV_GROSS_BOOKINGPOS,
NVL(SUM(SHIS.SHIS_NETFBREV),0) DEF_FB_REV_NET,
NVL(SUM(SHIS.SHIS_NETFBREV),0) DEF_FB_REV_NET_BOOKINGPOS,
0 TENT_FB_REV_NET,
0 TENT_FB_REV_NET_BOOKINGPOS,
NVL(SUM(SHIS.SHIS_GROSSMINIBARREV),0)+NVL(SUM(SHIS.SHIS_GROSSTELEREV),0)+NVL(SUM(SHIS.SHIS_GROSSMISCREV),0) DEF_OTHER_REV_GROSS,
NVL(SUM(SHIS.SHIS_GROSSMINIBARREV),0)+NVL(SUM(SHIS.SHIS_GROSSTELEREV),0)+NVL(SUM(SHIS.SHIS_GROSSMISCREV),0) DEF_OTH_REV_GROSS_BOOKPOS,
0 TENT_OTHER_REV_GROSS,
0 TENT_OTH_REV_GROSS_BOOKPOS,
NVL(SUM(SHIS.SHIS_NETMINIBARREV),0)+NVL(SUM(SHIS.SHIS_NETTELEREV),0)+NVL(SUM(SHIS.SHIS_NETMISCREV),0) DEF_OTHER_REV_NET,
NVL(SUM(SHIS.SHIS_NETMINIBARREV),0)+NVL(SUM(SHIS.SHIS_NETTELEREV),0)+NVL(SUM(SHIS.SHIS_NETMISCREV),0) DEF_OTH_REV_NET_BOOKPOS,
0 TENT_OTHER_REV_NET,
0 TENT_OTH_REV_NET_BOOKPOS, 
NVL(SUM(SHIS.SHIS_GROSSREV),0) DEF_REV_GROSS,
NVL(SUM(SHIS.SHIS_GROSSREV),0) DEF_REV_GROSS_BOOKINGPOS,
0 TENT_REV_GROSS,
0 TENT_REV_GROSS_BOOKINGPOS,
NVL(SUM(SHIS.SHIS_NETREV),0) DEF_REV_NET,
NVL(SUM(SHIS.SHIS_NETREV),0) DEF_REV_NET_BOOKINGPOS,
0 TENT_REV_NET,
0 TENT_REV_NET_BOOKINGPOS,
0 DAYUSE_RMS_DEF, 
0 DAYUSE_RMS_TENT,  
0 ARR_DAYUSE_RMS_DEF_TENT, 
0 ARR_DAYUSE_RMS_DEF,
0 DEP_DAYUSE_RMS_DEF_TENT,  
0 DEP_DAYUSE_RMS_DEF,
0 DAYUSE_ADLT_DEF, 
0 DAYUSE_ADLT_TENT,
0 DAYUSE_CHILDS_DEF, 
0 DAYUSE_CHILDS_TENT,
0 BLOCK_ALL_DEF, 
0 BLOCK_ALL_TENT,
0 BLOCK_NOT_PICKUP_DEF,
0 BLOCK_NOT_PICKUP_TENT,
0 BLOCK_PICKUP_DEF,
0 BLOCK_PICKUP_TENT
from
V8_REP_WDAT_DATE_XCMA WDAT,SHIS
 where
 shis.SHIS_WDAT_DATE=WDAT.WDAT_DATE AND
 shis.SHIS_YDET_XCMA_ID=WDAT.XCMA_ID
 group by wdat.wdat_date, wdat.xcma_id, WDAT.XCMA_XCMM_ID
)
union all
(
select
S_POSDATE                                                                     WDAT_DATE, 
S_POSDATE                                                                     WDAT_DATE2, 
S_POSDATE                                                                     WDAT_DATE3, 
TO_CHAR(S_POSDATE,'yyyy_mm')                                     MONTHYEAR,
case when S_POSDATE>=(select wgbs_datevalue from wgbs) then 1 else 0 end      FUTURE, 
S_XCMA_ID                                                                      XCMA_ID,
S_XCMM_ID                                                                      XCMM_ID,
sum(S_OCC_ROOMS_DEF)                                                OCC_ROOMS_DEF, 
sum(S_OCC_ROOMS_DEF_BOOKINGPOS)                           OCC_ROOMS_DEF_BOOKINGPOS,
sum(S_OCC_ROOMS_TENT)                                             OCC_ROOMS_TENT,
sum(S_OCC_ROOMS_TENT_BOOKINGPOS)                         OCC_ROOMS_TENT_BOOKINGPOS,
sum(S_ARR_ROOMS_DEF_TENT)                                                     ARR_ROOMS_DEF_TENT,
sum(S_ARR_ROOMS_DEF)                                                          ARR_ROOMS_DEF, 
sum(S_DEP_ROOMS_DEF_TENT)                                                     DEP_ROOMS_DEF_TENT,
sum(S_DEP_ROOMS_DEF)                                                          DEP_ROOMS_DEF,
sum(S_OCC_ADULTS_DEF)                                                         OCC_ADULTS_DEF,
sum(S_OCC_ADULTS_DEF_BOOKINGPOS)                                    OCC_ADULTS_DEF_BOOKINGPOS,
sum(S_OCC_ADULTS_TENT)                                                        OCC_ADULTS_TENT,
sum(S_OCC_ADULTS_TENT_BOOKINGPOS)                                    OCC_ADULTS_TENT_BOOKINGPOS,
sum(S_BUD_NOOFADULTS)                                                       BUD_NOOFADULTS,
sum(S_OCC_CHILDS_DEF)                                                         OCC_CHILDS_DEF,
sum(S_OCC_CHILDS_TENT)                                                        OCC_CHILDS_TENT, 
sum(S_DEF_ARR_ADULTS)                                                           DEF_ARR_ADULTS,
sum(S_TENT_ARR_ADULTS)                                                      TENT_ARR_ADULTS,
sum(S_DEF_ARR_KIDS)                                                             DEF_ARR_KIDS,
sum(S_TENT_ARR_KIDS)                                                           TENT_ARR_KIDS,
sum(S_BUD_REV_GROSS)                                                        BUD_REV_GROSS,
sum(S_BUD_REV_NET)                                                              BUD_REV_NET,
sum(S_DEF_ROOM_REV_GROSS)                                               DEF_ROOM_REV_GROSS,
sum(S_DEF_RM_REV_GROSS_BOOKINGPOS)                              DEF_RM_REV_GROSS_BOOKINGPOS,
sum(S_TENT_ROOM_REV_GROSS)                                           TENT_ROOM_REV_GROSS,
sum(S_TENT_RM_REV_GROSS_BOOKINGPOS)                       TENT_RM_REV_GROSS_BOOKINGPOS,
sum(S_DEF_ROOM_REV_NET)                                                 DEF_ROOM_REV_NET,
sum(S_DEF_RM_REV_NET_BOOKINGPOS)                              DEF_RM_REV_NET_BOOKINGPOS,
sum(S_TENT_ROOM_REV_NET)                                                TENT_ROOM_REV_NET,
sum(S_TENT_RM_REV_NET_BOOKINGPOS)                             TENT_RM_REV_NET_BOOKINGPOS,
sum(S_DEF_FB_REV_GROSS)                                                     DEF_FB_REV_GROSS,
sum(S_DEF_FB_REV_GROSS_BOOKINGPOS)                              DEF_FB_REV_GROSS_BOOKINGPOS,
sum(S_TENT_FB_REV_GROSS)                                                TENT_FB_REV_GROSS,
sum(S_TENT_FB_REV_GROSS_BOOKINGPOS)                             TENT_FB_REV_GROSS_BOOKINGPOS,
sum(S_DEF_FB_REV_NET)                                                       DEF_FB_REV_NET,
sum(S_DEF_FB_REV_NET_BOOKINGPOS)                                    DEF_FB_REV_NET_BOOKINGPOS,
sum(S_TENT_FB_REV_NET)                                                      TENT_FB_REV_NET,
sum(S_TENT_FB_REV_NET_BOOKINGPOS)                                  TENT_FB_REV_NET_BOOKINGPOS,
sum(S_DEF_OTHER_REV_GROSS)                                              DEF_OTHER_REV_GROSS,
sum(S_DEF_OTH_REV_GROSS_BOOKPOS)                             DEF_OTH_REV_GROSS_BOOKPOS,
sum(S_TENT_OTHER_REV_GROSS)                                             TENT_OTHER_REV_GROSS,
sum(S_TENT_OTH_REV_GROSS_BOOKPOS)                            TENT_OTH_REV_GROSS_BOOKPOS,
sum(S_DEF_OTHER_REV_NET)                                                    DEF_OTHER_REV_NET,
sum(S_DEF_OTH_REV_NET_BOOKPOS)                                   DEF_OTH_REV_NET_BOOKPOS,
sum(S_TENT_OTHER_REV_NET)                                                   TENT_OTHER_REV_NET,
sum(S_TENT_OTH_REV_NET_BOOKPOS)                                  TENT_OTH_REV_NET_BOOKPOS,
sum(S_DEF_REV_GROSS)                                                     DEF_REV_GROSS,
sum(S_DEF_REV_GROSS_BOOKINGPOS)                                  DEF_REV_GROSS_BOOKINGPOS,
sum(S_TENT_REV_GROSS)                                                 TENT_REV_GROSS,
sum(S_TENT_REV_GROSS_BOOKINGPOS)                             TENT_REV_GROSS_BOOKINGPOS,
sum(S_DEF_REV_NET)                                                       DEF_REV_NET,
sum(S_DEF_REV_NET_BOOKINGPOS)                                   DEF_REV_NET_BOOKINGPOS,
sum(S_TENT_REV_NET)                                                      TENT_REV_NET,
sum(S_TENT_REV_NET_BOOKINGPOS)                                  TENT_REV_NET_BOOKINGPOS,
sum(S_DAYUSE_RMS_DEF)                                                       DAYUSE_RMS_DEF, 
sum(S_DAYUSE_RMS_TENT)                                                       DAYUSE_RMS_TENT,  
sum(S_ARR_DAYUSE_RMS_DEF_TENT)                                       ARR_DAYUSE_RMS_DEF_TENT, 
sum(S_ARR_DAYUSE_RMS_DEF)                                               ARR_DAYUSE_RMS_DEF ,
sum(S_DEP_DAYUSE_RMS_DEF_TENT)                                       DEP_DAYUSE_RMS_DEF_TENT,  
sum(S_DEP_DAYUSE_RMS_DEF)                                               DEP_DAYUSE_RMS_DEF,
sum(S_DAYUSE_ADLT_DEF)                                                      DAYUSE_ADLT_DEF , 
sum(S_DAYUSE_ADLT_TENT)                                                 DAYUSE_ADLT_TENT,
sum(S_DAYUSE_CHILDS_DEF)                                                 DAYUSE_CHILDS_DEF , 
sum(S_DAYUSE_CHILDS_TENT)                                              DAYUSE_CHILDS_TENT,
sum(S_BLOCK_ALL_DEF)                                                                BLOCK_ALL_DEF, 
sum(S_BLOCK_ALL_TENT)                                                               BLOCK_ALL_TENT,
sum(S_BLOCK_NOT_PICKUP_DEF)                                                 BLOCK_NOT_PICKUP_DEF,
sum(S_BLOCK_NOT_PICKUP_TENT)                                               BLOCK_NOT_PICKUP_TENT,
sum(S_BLOCK_PICKUP_DEF)                                                        BLOCK_PICKUP_DEF,
sum(S_BLOCK_PICKUP_TENT)                                                        BLOCK_PICKUP_TENT
from
(
select
WDAT.WDAT_DATE                                                               S_POSDATE,
WDAT.XCMA_ID                                                                 S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                                       S_XCMM_ID,
nvl(S_REP_YBLD_OCC_XCMA.S_DEFNOOFROOMS,0)+nvl(S_REP_YDET_OCC_WB_XCMA.S_DEFNOOFROOMS,0)                                                                                                                                                                                 S_OCC_ROOMS_DEF,
nvl(S_REP_YBLD_OCC_XCMA.S_DEFNOOFROOMS,0)+nvl(S_REP_YDET_OCC_WB_XCMA.S_DEFNOOFROOMS,0)+nvl(S_REP_YBLD_OCC_XCMA.S_DEFNOOFROOMSBOOKINGPOSAVAIL,0)                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS, 
nvl(S_REP_YBLD_OCC_XCMA.S_TENTNOOFROOMS,0)+nvl(S_REP_YDET_OCC_WB_XCMA.S_TENTNOOFROOMS,0)-nvl(S_REP_YDET_OCC_WB_XCMA.S_TENTBLOCKDEFRESROOM,0)                                                                            S_OCC_ROOMS_TENT,
nvl(S_REP_YBLD_OCC_XCMA.S_TENTNOOFROOMS,0)+nvl(S_REP_YDET_OCC_WB_XCMA.S_TENTNOOFROOMS,0)+nvl(S_REP_YBLD_OCC_XCMA.S_TENTNOOFROOMSBOOKINGPOSAVAIL,0)-nvl(S_REP_YDET_OCC_WB_XCMA.S_TENTBLOCKDEFRESROOM,0)                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
nvl(S_REP_YDET_OCC_WB_XCMA.S_DEFNOOFROOMSDAYUSE,0)                                  S_DAYUSE_RMS_DEF,   
nvl(S_REP_YDET_OCC_WB_XCMA.S_TENTNOOFROOMSDAYUSE,0)                                 S_DAYUSE_RMS_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
nvl(S_REP_YBLD_OCC_XCMA.S_DEFNOOFROOMS,0)        S_BLOCK_ALL_DEF,
nvl(S_REP_YBLD_OCC_XCMA.S_TENTNOOFROOMS,0)                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
 from 
 V8_REP_WDAT_DATE_XCMA wdat,
( select 
V8_REP_YBLD_OCC_XCMA.YBLD_DATE S_YBLD_DATE,
V8_REP_YBLD_OCC_XCMA.YBLH_XCMA_ID S_XCMA_ID,
sum(V8_REP_YBLD_OCC_XCMA.DEFNOOFROOMS) S_DEFNOOFROOMS, 
sum(V8_REP_YBLD_OCC_XCMA.DEFNOOFROOMSBOOKINGPOSAVAIL) S_DEFNOOFROOMSBOOKINGPOSAVAIL,
sum(V8_REP_YBLD_OCC_XCMA.TENTNOOFROOMS) S_TENTNOOFROOMS,
sum(V8_REP_YBLD_OCC_XCMA.TENTNOOFROOMSBOOKINGPOSAVAIL) S_TENTNOOFROOMSBOOKINGPOSAVAIL
 from V8_REP_YBLD_OCC_XCMA
 group by V8_REP_YBLD_OCC_XCMA.YBLD_DATE, V8_REP_YBLD_OCC_XCMA.YBLH_XCMA_ID) S_REP_YBLD_OCC_XCMA,
 ( select 
V8_REP_YDET_OCC_WB_XCMA.YDET_DATE S_YDET_DATE,
V8_REP_YDET_OCC_WB_XCMA.YDET_XCMA_ID S_XCMA_ID,
sum(V8_REP_YDET_OCC_WB_XCMA.DEFNOOFROOMS) S_DEFNOOFROOMS, 
sum(V8_REP_YDET_OCC_WB_XCMA.DEFNOOFROOMSDAYUSE) S_DEFNOOFROOMSDAYUSE,
sum(V8_REP_YDET_OCC_WB_XCMA.TENTNOOFROOMS) S_TENTNOOFROOMS,
sum(V8_REP_YDET_OCC_WB_XCMA.TENTNOOFROOMSDAYUSE) S_TENTNOOFROOMSDAYUSE,
sum(V8_REP_YDET_OCC_WB_XCMA.TENTBLOCKDEFRESROOM) S_TENTBLOCKDEFRESROOM
 from V8_REP_YDET_OCC_WB_XCMA
 group by V8_REP_YDET_OCC_WB_XCMA.YDET_DATE,V8_REP_YDET_OCC_WB_XCMA.YDET_XCMA_ID ) S_REP_YDET_OCC_WB_XCMA
 where
 WDAT.WDAT_DATE=S_REP_YBLD_OCC_XCMA.S_YBLD_DATE(+) and
 WDAT.XCMA_ID = S_REP_YBLD_OCC_XCMA.S_XCMA_ID(+) and
 WDAT.WDAT_DATE=S_REP_YDET_OCC_WB_XCMA.S_YDET_DATE(+)
 and WDAT.XCMA_ID = S_REP_YDET_OCC_WB_XCMA.S_XCMA_ID(+)
union all
select 
V8_REP_HS_ARR_DEP_COMB_SM_XCMA.WDAT_DATE                                     S_POSDATE,
V8_REP_HS_ARR_DEP_COMB_SM_XCMA.XCMA_ID                                       S_XCMA_ID,
V8_REP_HS_ARR_DEP_COMB_SM_XCMA.XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
V8_REP_HS_ARR_DEP_COMB_SM_XCMA.ARREXPROOM                                    S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,
V8_REP_HS_ARR_DEP_COMB_SM_XCMA.DEPEXPROOM                                    S_DEP_ROOMS_DEF_TENT, 
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
V8_REP_HS_ARR_DEP_COMB_SM_XCMA.ARREXPROOMDAYUSE                                                                S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
V8_REP_HS_ARR_DEP_COMB_SM_XCMA.DEPEXPROOMDAYUSE                                                                S_DEP_DAYUSE_RMS_DEF_TENT,    
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from V8_REP_HS_ARR_DEP_COMB_SM_XCMA
union all
select 
V8_REP_HS_ARR_ALLROOM_XCMA.WDAT_DATE                                          S_POSDATE,
V8_REP_HS_ARR_ALLROOM_XCMA.XCMA_ID                                            S_XCMA_ID,
V8_REP_HS_ARR_ALLROOM_XCMA.XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
V8_REP_HS_ARR_ALLROOM_XCMA.DEFEXPROOM                                         S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
V8_REP_HS_ARR_ALLROOM_XCMA.DEFEXPROOMDAYUSE                                                                            S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from V8_REP_HS_ARR_ALLROOM_XCMA
union all
select
V8_REP_HS_DEP_ALLROOM_XCMA.WDAT_DATE                                          S_POSDATE,
V8_REP_HS_DEP_ALLROOM_XCMA.XCMA_ID                                            S_XCMA_ID,
V8_REP_HS_DEP_ALLROOM_XCMA.XCMM_ID                                                    S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
V8_REP_HS_DEP_ALLROOM_XCMA.DEFDEPROOM                                         S_DEP_ROOMS_DEF,
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
V8_REP_HS_DEP_ALLROOM_XCMA.DEFDEPROOMDAYUSE                                                                            S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from V8_REP_HS_DEP_ALLROOM_XCMA
union all
select
WDAT.WDAT_DATE                                                               S_POSDATE,
WDAT.XCMA_ID                                                                 S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF,
nvl(S_REP_YDET_ADULT_WB_XCMA.S_DEFADULTNO,0)-nvl(S_REP_YDET_ADULT_WB_XCMA.S_DEFBLOCKSUBSTRACT,0)+nvl(S_REP_YBLD_OCC_XCMA.S_DEFNOOFADULTS,0)    S_OCC_ADULTS_DEF, 
nvl(S_REP_YBLD_OCC_XCMA.S_DEFNOOFADULTSBOOKPOSAVAIL,0)+nvl(S_REP_YDET_ADULT_WB_XCMA.S_DEFADULTNO,0)                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
nvl(S_REP_YDET_ADULT_WB_XCMA.S_TENTADULTNO,0)-nvl(S_REP_YDET_ADULT_WB_XCMA.S_TENTBLOCKSUBSTRACT,0)+nvl(S_REP_YBLD_OCC_XCMA.S_TENTNOOFADULTS,0) S_OCC_ADULTS_TENT,
nvl(S_REP_YBLD_OCC_XCMA.S_TENTNOOFADULTSBOOKPOSAVAIL,0)+nvl(S_REP_YDET_ADULT_WB_XCMA.S_TENTADULTNO,0)                                                                           S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
nvl(S_REP_YDET_ADULT_WB_XCMA.S_DEFADULTNODAYUSE,0)                                                                            S_DAYUSE_ADLT_DEF, 
nvl(S_REP_YDET_ADULT_WB_XCMA.S_TENTADULTNODAYUSE,0)                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from 
V8_REP_WDAT_DATE_XCMA wdat,
( select 
V8_REP_YBLD_OCC_XCMA.YBLD_DATE S_YBLD_DATE,
V8_REP_YBLD_OCC_XCMA.YBLH_XCMA_ID S_XCMA_ID,
sum(V8_REP_YBLD_OCC_XCMA.DEFNOOFADULTS) S_DEFNOOFADULTS, 
sum(V8_REP_YBLD_OCC_XCMA.DEFNOOFADULTSBOOKINGPOSAVAIL) S_DEFNOOFADULTSBOOKPOSAVAIL,
sum(V8_REP_YBLD_OCC_XCMA.TENTNOOFADULTS) S_TENTNOOFADULTS,
sum(V8_REP_YBLD_OCC_XCMA.TENTNOOFADULTSBOOKINGPOSAVAIL) S_TENTNOOFADULTSBOOKPOSAVAIL
 from V8_REP_YBLD_OCC_XCMA
 group by V8_REP_YBLD_OCC_XCMA.YBLD_DATE, V8_REP_YBLD_OCC_XCMA.YBLH_XCMA_ID) S_REP_YBLD_OCC_XCMA,
 ( select 
V8_REP_YDET_ADULT_WB_XCMA.YDET_DATE S_YDET_DATE,
V8_REP_YDET_ADULT_WB_XCMA.YDET_XCMA_ID S_XCMA_ID,
sum(V8_REP_YDET_ADULT_WB_XCMA.DEFADULTNO) S_DEFADULTNO,
sum(V8_REP_YDET_ADULT_WB_XCMA.DEFADULTNODAYUSE) S_DEFADULTNODAYUSE,
sum(V8_REP_YDET_ADULT_WB_XCMA.TENTADULTNO) S_TENTADULTNO,
sum(V8_REP_YDET_ADULT_WB_XCMA.TENTADULTNODAYUSE) S_TENTADULTNODAYUSE,
sum(V8_REP_YDET_ADULT_WB_XCMA.DEFBLOCKSUBSTRACT) S_DEFBLOCKSUBSTRACT,
sum(V8_REP_YDET_ADULT_WB_XCMA.TENTBLOCKSUBSTRACT) S_TENTBLOCKSUBSTRACT
 from V8_REP_YDET_ADULT_WB_XCMA
 group by V8_REP_YDET_ADULT_WB_XCMA.YDET_DATE, V8_REP_YDET_ADULT_WB_XCMA.YDET_XCMA_ID ) S_REP_YDET_ADULT_WB_XCMA
 where
 WDAT.WDAT_DATE=S_REP_YBLD_OCC_XCMA.S_YBLD_DATE(+) and
 WDAT.XCMA_ID = S_REP_YBLD_OCC_XCMA.S_XCMA_ID(+) and
 WDAT.WDAT_DATE=S_REP_YDET_ADULT_WB_XCMA.S_YDET_DATE(+) and
 WDAT.XCMA_ID = S_REP_YDET_ADULT_WB_XCMA.S_XCMA_ID(+)
union all
select 
WDAT.WDAT_DATE                                                               S_POSDATE,
WDAT.XCMA_ID                                                                 S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
nvl(SBUD_VALUE,0)                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
sbud, V8_REP_WDAT_DATE_XCMA wdat
where sbud.SBUD_DATE=WDAT.WDAT_DATE and 
upper(sbud.SBUD_TABLENAME)='XCMA' and 
sbud.SBUD_TABLE_ID=WDAT.XCMA_ID 
and sbud.SBUD_TYPE=4
union all
select
WDAT.WDAT_DATE                                                             S_POSDATE,
WDAT.XCMA_ID                                               S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                   S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
sum(decode(YRES.YRES_RESSTATUS,1,YRGL.YRGL_NUMBER*YDET.YDET_NOOFROOMS,0))    S_OCC_CHILDS_DEF,
sum(decode(YRES.YRES_RESSTATUS,0,YRGL.YRGL_NUMBER*YDET.YDET_NOOFROOMS,0))    S_OCC_CHILDS_TENT,
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
YDET,YRGL,YRES,XCAC, V8_REP_WDAT_DATE_XCMA WDAT
WHERE YRGL.yrgl_ydet_id=YDET.ydet_id  AND 
YRES.yres_id=YDET.ydet_yres_id AND 
XCAC.xcac_id=yrgl_xcac_id AND 
YDET.YDET_DATE=WDAT.WDAT_DATE AND 
YDET.YDET_XCMA_ID=WDAT.XCMA_ID
GROUP BY WDAT.WDAT_DATE, WDAT.XCMA_ID, WDAT.XCMA_XCMM_ID
union all
select 
WDAT.WDAT_DATE                                                             S_POSDATE,
WDAT.XCMA_ID                                               S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                   S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF,
0                                                                             S_OCC_CHILDS_TENT,
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
sum(decode(YRES.YRES_RESSTATUS,1,YRGL.YRGL_NUMBER*YDET.YDET_NOOFROOMS,0))                                                                                S_DAYUSE_CHILDS_DEF, 
sum(decode(YRES.YRES_RESSTATUS,0,YRGL.YRGL_NUMBER*YDET.YDET_NOOFROOMS,0))                                                                                S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
YDET,YRGL,YRES,XCAC, V8_REP_WDAT_DATE_XCMA WDAT
WHERE YRGL.yrgl_ydet_id=YDET.ydet_id  AND 
YRES.yres_id=YDET.ydet_yres_id AND 
XCAC.xcac_id=yrgl_xcac_id AND 
YDET.YDET_DATE=WDAT.WDAT_DATE AND 
YRES.YRES_EXPARRTIME = YRES.YRES_EXPDEPTIME AND
YDET.YDET_XCMA_ID=WDAT.XCMA_ID
GROUP BY WDAT.WDAT_DATE, WDAT.XCMA_ID, WDAT.XCMA_XCMM_ID
union all 
select
V8_REP_HS_ARR_ALLADULT_XCMA.WDAT_DATE                                                             S_POSDATE,
V8_REP_HS_ARR_ALLADULT_XCMA.XCMA_ID                                               S_XCMA_ID,
V8_REP_HS_ARR_ALLADULT_XCMA.XCMM_ID                                   S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
V8_REP_HS_ARR_ALLADULT_XCMA.defexpadult                                                                             S_DEF_ARR_ADULTS,
V8_REP_HS_ARR_ALLADULT_XCMA.tentexpadult                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_HS_ARR_ALLADULT_XCMA
union all
select
V8_REP_HS_ARR_ALLCHILD_XCMA.WDAT_DATE                                                             S_POSDATE,
V8_REP_HS_ARR_ALLCHILD_XCMA.XCMA_ID                                               S_XCMA_ID,
V8_REP_HS_ARR_ALLCHILD_XCMA.XCMM_ID                         S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
V8_REP_HS_ARR_ALLCHILD_XCMA.DEFARRCHILD        S_DEF_ARR_KIDS,
V8_REP_HS_ARR_ALLCHILD_XCMA.TENTARRCHILD      S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_HS_ARR_ALLCHILD_XCMA
union all
select
WDAT.WDAT_DATE                                                             S_POSDATE,
WDAT.XCMA_ID                                               S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                   S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
nvl(sbud.SBUD_VALUE,0)                                          S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from sbud,V8_REP_WDAT_DATE_XCMA wdat 
where sbud.SBUD_DATE=WDAT.WDAT_DATE and 
upper(sbud.SBUD_TABLENAME)='XCMA' and 
sbud.SBUD_TABLE_ID=WDAT.XCMA_ID and 
sbud.SBUD_TYPE=2                                                                            
union all
select
WDAT.WDAT_DATE                                                             S_POSDATE,
WDAT.XCMA_ID                                               S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                   S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
nvl(sbud.SBUD_VALUE,0)                                          S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from sbud, V8_REP_WDAT_DATE_XCMA wdat
where sbud.SBUD_DATE=wdat.WDAT_DATE and 
upper(sbud.SBUD_TABLENAME)='XCMA' and 
sbud.SBUD_TABLE_ID=WDAT.XCMA_ID and 
sbud.SBUD_TYPE=1                                                                       
union all
select 
V.YPOS_DATE                                                                  S_POSDATE,
V.XCMA_ID                                                                    S_XCMA_ID,
V.XCMM_ID                                                               S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
V.DEF_REV_GROSS                                                   S_DEV_ROOM_REV_GROSS,
V.DEF_REV_GROSS_BOOKINGPOS                               S_DEF_RM_REV_GROSS_BOOKINGPOS,
V.TENT_REV_GROSS                                                 S_TENT_ROOM_REV_GROSS,
V.TENT_REV_GROSS_BOOKINGPOS                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
V.DEF_REV_NET                                                       S_DEF_ROOM_REV_NET,
V.DEF_REV_NET_BOOKINGPOS                                  S_DEF_RM_REV_NET_BOOKINGPOS,
V.TENT_REV_NET                                                     S_TENT_ROOM_REV_NET,
V.TENT_REV_NET_BOOKINGPOS                                S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YPOS_FC_XCMA_STATYPE1 V 
union all 
select 
V.YPOS_DATE                                                                  S_POSDATE,
V.XCMA_ID                                                                    S_XCMA_ID,
V.XCMM_ID                                                               S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
V.DEF_REV_GROSS                                                   S_DEV_FB_REV_GROSS,
V.DEF_REV_GROSS_BOOKINGPOS                               S_DEF_FB_REV_GROSS_BOOKINGPOS,
V.TENT_REV_GROSS                                                S_TENT_FB_REV_GROSS,
V.TENT_REV_GROSS_BOOKINGPOS                            S_TENT_FB_REV_GROSS_BOOKINGPOS,
V.DEF_REV_NET                                                        S_DEV_FB_REV_NET,
V.DEF_REV_NET_BOOKINGPOS                              S_DEF_FB_REV_NET_BOOKINGPOS,
V.TENT_REV_NET                                                     S_TENT_FB_REV_NET,
V.TENT_REV_NET_BOOKINGPOS                               S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YPOS_FC_XCMA_STATYPE2 V 
union all
select 
V.YPOS_DATE                                                                  S_POSDATE,
V.XCMA_ID                                                                    S_XCMA_ID,
V.XCMM_ID                                                               S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
V.DEF_REV_GROSS                                                    S_DEF_OTHER_REV_GROSS,
V.DEF_REV_GROSS_BOOKINGPOS                              S_DEF_OTH_REV_GROSS_BOOKPOS,
V.TENT_REV_GROSS                                                S_TENT_OTHER_REV_GROSS,
V.TENT_REV_GROSS_BOOKINGPOS                            S_TENT_OTH_REV_GROSS_BOOKPOS,
V.DEF_REV_NET                                                        S_DEF_OTHER_REV_NET,
V.DEF_REV_NET_BOOKINGPOS                              S_DEF_OTH_REV_NET_BOOKPOS,
V.TENT_REV_NET                                                     S_TENT_OTHER_REV_NET,
V.TENT_REV_NET_BOOKINGPOS                                S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YPOS_FC_XCMA_STATYPE345 V
union all
select 
V.YPOS_DATE                                                                  S_POSDATE,
V.XCMA_ID                                                                    S_XCMA_ID,
V.XCMM_ID                                                               S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                              S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
V.DEF_REV_GROSS                                                 S_DEF_REV_GROSS,
V.DEF_REV_GROSS_BOOKINGPOS                            S_DEF_REV_GROSS_BOOKINGPOS,
V.TENT_REV_GROSS                                               S_TENT_REV_GROSS,
V.TENT_REV_GROSS_BOOKINGPOS                          S_TENT_REV_GROSS_BOOKINGPOS,
V.DEF_REV_NET                                                      S_DEF_REV_NET,
V.DEF_REV_NET_BOOKINGPOS                                 S_DEF_REV_NET_BOOKINGPOS,
V.TENT_REV_NET                                                   S_TENT_REV_NET,
V.TENT_REV_NET_BOOKINGPOS                              S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YPOS_FC_XCMA V
union all
select 
WDAT.WDAT_DATE                                                   S_POSDATE,
WDAT.XCMA_ID                                                         S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
V8_REP_YBLD_NOT_PICKUP_XCMA.DEFNOOFROOMS     S_BLOCK_NOT_PICKUP_DEF,
V8_REP_YBLD_NOT_PICKUP_XCMA.TENTNOOFROOMS   S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YBLD_NOT_PICKUP_XCMA,
V8_REP_WDAT_DATE_XCMA WDAT
where
WDAT.WDAT_DATE=V8_REP_YBLD_NOT_PICKUP_XCMA.YBLD_DATE(+) and
WDAT.XCMA_ID=V8_REP_YBLD_NOT_PICKUP_XCMA.XCMA_ID(+)
union all
select
WDAT.WDAT_DATE                                                   S_POSDATE,
WDAT.XCMA_ID                                                         S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
V8_REP_YBLD_PICKUP_XCMA.DEFNOOFROOMS            S_BLOCK_PICKUP_DEF,
V8_REP_YBLD_PICKUP_XCMA.TENTNOOFROOMS          S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED 
from
V8_REP_YBLD_PICKUP_XCMA,
V8_REP_WDAT_DATE_XCMA WDAT
where
WDAT.WDAT_DATE=V8_REP_YBLD_PICKUP_XCMA.YBLD_DATE(+) and
WDAT.XCMA_ID=V8_REP_YBLD_PICKUP_XCMA.XCMA_ID(+)
union all
select
WDAT_DATE                                                          S_POSDATE,
XCMA_ID                                                                S_XCMA_ID,
XCMA_XCMM_ID                                                                 S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_BUD_NOOFADULTS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                             S_BUD_REV_GROSS,
0                                                                             S_BUD_REV_NET,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED 
from
V8_REP_WDAT_DATE_XCMA WDAT
) where not exists (select 1 from SHIS where SHIS.SHIS_WDAT_DATE=S_POSDATE and SHIS.SHIS_YDET_XCMA_ID = S_XCMA_ID) 
group by S_POSDATE, S_XCMA_ID, S_XCMM_ID
) order by wdat_date, xcma_id;

CREATE OR REPLACE VIEW V8_REP_REV_HF_HUGE_XCMA_CAD
AS
select
WDAT_DATE    WDAT_DATE,
WDAT_DATE2    WDAT_DATE2,
WDAT_DATE3    WDAT_DATE3,
MONTHYEAR    MONTHYEAR,
FUTURE    FUTURE,
YCAD_ID YCAD_ID,
XCMA_ID    XCMA_ID,
XCMM_ID     XCMM_ID,
OCC_ROOMS_DEF    OCC_ROOMS_DEF,
OCC_ROOMS_DEF_BOOKINGPOS    OCC_ROOMS_DEF_BOOKINGPOS,
OCC_ROOMS_TENT    OCC_ROOMS_TENT,
OCC_ROOMS_TENT_BOOKINGPOS    OCC_ROOMS_TENT_BOOKINGPOS,
ARR_ROOMS_DEF_TENT    ARR_ROOMS_DEF_TENT,
ARR_ROOMS_DEF    ARR_ROOMS_DEF,
DEP_ROOMS_DEF_TENT    DEP_ROOMS_DEF_TENT,
DEP_ROOMS_DEF    DEP_ROOMS_DEF,
OCC_ADULTS_DEF    OCC_ADULTS_DEF,
OCC_ADULTS_DEF_BOOKINGPOS    OCC_ADULTS_DEF_BOOKINGPOS,
OCC_ADULTS_TENT    OCC_ADULTS_TENT,
OCC_ADULTS_TENT_BOOKINGPOS    OCC_ADULTS_TENT_BOOKINGPOS,
OCC_CHILDS_DEF    OCC_CHILDS_DEF,
OCC_CHILDS_TENT    OCC_CHILDS_TENT,
DEF_ARR_ADULTS    DEF_ARR_ADULTS,
TENT_ARR_ADULTS    TENT_ARR_ADULTS,
DEF_ARR_KIDS    DEF_ARR_KIDS,
TENT_ARR_KIDS    TENT_ARR_KIDS,
DEF_ROOM_REV_GROSS    DEF_ROOM_REV_GROSS,
DEF_RM_REV_GROSS_BOOKINGPOS    DEF_RM_REV_GROSS_BOOKINGPOS,
TENT_ROOM_REV_GROSS    TENT_ROOM_REV_GROSS,
TENT_RM_REV_GROSS_BOOKINGPOS    TENT_RM_REV_GROSS_BOOKINGPOS,
DEF_ROOM_REV_NET    DEF_ROOM_REV_NET,
DEF_RM_REV_NET_BOOKINGPOS    DEF_RM_REV_NET_BOOKINGPOS,
TENT_ROOM_REV_NET    TENT_ROOM_REV_NET,
TENT_RM_REV_NET_BOOKINGPOS    TENT_RM_REV_NET_BOOKINGPOS,
DEF_FB_REV_GROSS    DEF_FB_REV_GROSS,
DEF_FB_REV_GROSS_BOOKINGPOS    DEF_FB_REV_GROSS_BOOKINGPOS,
TENT_FB_REV_GROSS    TENT_FB_REV_GROSS,
TENT_FB_REV_GROSS_BOOKINGPOS    TENT_FB_REV_GROSS_BOOKINGPOS,
DEF_FB_REV_NET    DEF_FB_REV_NET,
DEF_FB_REV_NET_BOOKINGPOS    DEF_FB_REV_NET_BOOKINGPOS,
TENT_FB_REV_NET    TENT_FB_REV_NET,
TENT_FB_REV_NET_BOOKINGPOS    TENT_FB_REV_NET_BOOKINGPOS,
DEF_OTHER_REV_GROSS    DEF_OTHER_REV_GROSS,
DEF_OTH_REV_GROSS_BOOKPOS    DEF_OTH_REV_GROSS_BOOKPOS,
TENT_OTHER_REV_GROSS    TENT_OTHER_REV_GROSS,
TENT_OTH_REV_GROSS_BOOKPOS    TENT_OTH_REV_GROSS_BOOKPOS,
DEF_OTHER_REV_NET    DEF_OTHER_REV_NET,
DEF_OTH_REV_NET_BOOKPOS    DEF_OTH_REV_NET_BOOKPOS,
TENT_OTHER_REV_NET    TENT_OTHER_REV_NET,
TENT_OTH_REV_NET_BOOKPOS    TENT_OTH_REV_NET_BOOKPOS,
DEF_REV_GROSS                           DEF_REV_GROSS,
DEF_REV_GROSS_BOOKINGPOS       DEF_REV_GROSS_BOOKINGPOS,
TENT_REV_GROSS                          TENT_REV_GROSS,
TENT_REV_GROSS_BOOKINGPOS       TENT_REV_GROSS_BOOKINGPOS,
DEF_REV_NET                                 DEF_REV_NET,
DEF_REV_NET_BOOKINGPOS              DEF_REV_NET_BOOKINGPOS,
TENT_REV_NET                                TENT_REV_NET,
TENT_REV_NET_BOOKINGPOS             TENT_REV_NET_BOOKINGPOS,
DAYUSE_RMS_DEF     DAYUSE_RMS_DEF, 
DAYUSE_RMS_TENT     DAYUSE_RMS_TENT, 
ARR_DAYUSE_RMS_DEF_TENT     ARR_DAYUSE_RMS_DEF_TENT, 
ARR_DAYUSE_RMS_DEF    ARR_DAYUSE_RMS_DEF,
DEP_DAYUSE_RMS_DEF_TENT    DEP_DAYUSE_RMS_DEF_TENT,
DEP_DAYUSE_RMS_DEF    DEP_DAYUSE_RMS_DEF,
DAYUSE_ADLT_DEF     DAYUSE_ADLT_DEF, 
DAYUSE_ADLT_TENT    DAYUSE_ADLT_TENT,
DAYUSE_CHILDS_DEF    DAYUSE_CHILDS_DEF,
DAYUSE_CHILDS_TENT    DAYUSE_CHILDS_TENT,
BLOCK_ALL_DEF    BLOCK_ALL_DEF,
BLOCK_ALL_TENT    BLOCK_ALL_TENT,
BLOCK_NOT_PICKUP_DEF    BLOCK_NOT_PICKUP_DEF,
BLOCK_NOT_PICKUP_TENT    BLOCK_NOT_PICKUP_TENT,
BLOCK_PICKUP_DEF    BLOCK_PICKUP_DEF,
BLOCK_PICKUP_TENT    BLOCK_PICKUP_TENT
from
(
select 
WDAT.WDAT_DATE WDAT_DATE, 
WDAT.WDAT_DATE WDAT_DATE2,
WDAT.WDAT_DATE WDAT_DATE3,
TO_CHAR(WDAT.WDAT_DATE,'yyyy_mm') MonthYear, 
WDAT.FUTURE FUTURE,
WDAT.YCAD_ID YCAD_ID,
WDAT.XCMA_ID XCMA_ID,
WDAT.XCMA_XCMM_ID XCMM_ID,
SHIS.NOOFROOMS OCC_ROOMS_DEF, 
SHIS.NOOFROOMS OCC_ROOMS_DEF_BOOKINGPOS,
0 OCC_ROOMS_TENT,
0 OCC_ROOMS_TENT_BOOKINGPOS,
SHIS.ARRIVALS ARR_ROOMS_DEF_TENT,
0 ARR_ROOMS_DEF,  
SHIS.DEPARTURES DEP_ROOMS_DEF_TENT,
0 DEP_ROOMS_DEF, 
SHIS.ADULTNO OCC_ADULTS_DEF, 
SHIS.ADULTNO OCC_ADULTS_DEF_BOOKINGPOS,
0 OCC_ADULTS_TENT,
0 OCC_ADULTS_TENT_BOOKINGPOS,
SHIS.KIDS OCC_CHILDS_DEF, 
0 OCC_CHILDS_TENT, 
0 DEF_ARR_ADULTS,
0 TENT_ARR_ADULTS,
0 DEF_ARR_KIDS,
0 TENT_ARR_KIDS,
SHIS.GROSSROOMREV DEF_ROOM_REV_GROSS,
SHIS.GROSSROOMREV DEF_RM_REV_GROSS_BOOKINGPOS,
0 TENT_ROOM_REV_GROSS,
0 TENT_RM_REV_GROSS_BOOKINGPOS,
SHIS.NETROOMREV DEF_ROOM_REV_NET,
SHIS.NETROOMREV DEF_RM_REV_NET_BOOKINGPOS,
0 TENT_ROOM_REV_NET,
0 TENT_RM_REV_NET_BOOKINGPOS,
SHIS.GROSSFBREV DEF_FB_REV_GROSS,
SHIS.GROSSFBREV DEF_FB_REV_GROSS_BOOKINGPOS,
0 TENT_FB_REV_GROSS,
0 TENT_FB_REV_GROSS_BOOKINGPOS,
SHIS.NETFBREV DEF_FB_REV_NET,
SHIS.NETFBREV DEF_FB_REV_NET_BOOKINGPOS,
0 TENT_FB_REV_NET,
0 TENT_FB_REV_NET_BOOKINGPOS,
SHIS.GROSSMINIBARREV+SHIS.GROSSTELEREV+SHIS.GROSSMISCREV DEF_OTHER_REV_GROSS,
SHIS.GROSSMINIBARREV+SHIS.GROSSTELEREV+SHIS.GROSSMISCREV DEF_OTH_REV_GROSS_BOOKPOS,
0 TENT_OTHER_REV_GROSS,
0 TENT_OTH_REV_GROSS_BOOKPOS,
SHIS.NETMINIBARREV+SHIS.NETTELEREV+SHIS.NETMISCREV DEF_OTHER_REV_NET,
SHIS.NETMINIBARREV+SHIS.NETTELEREV+SHIS.NETMISCREV DEF_OTH_REV_NET_BOOKPOS,
0 TENT_OTHER_REV_NET,
0 TENT_OTH_REV_NET_BOOKPOS, 
SHIS.GROSSREV DEF_REV_GROSS,
SHIS.GROSSREV DEF_REV_GROSS_BOOKINGPOS,
0 TENT_REV_GROSS,
0 TENT_REV_GROSS_BOOKINGPOS,
SHIS.NETREV DEF_REV_NET,
SHIS.NETREV DEF_REV_NET_BOOKINGPOS,
0 TENT_REV_NET,
0 TENT_REV_NET_BOOKINGPOS,
0 DAYUSE_RMS_DEF, 
0 DAYUSE_RMS_TENT,  
0 ARR_DAYUSE_RMS_DEF_TENT, 
0 ARR_DAYUSE_RMS_DEF,
0 DEP_DAYUSE_RMS_DEF_TENT,  
0 DEP_DAYUSE_RMS_DEF,
0 DAYUSE_ADLT_DEF, 
0 DAYUSE_ADLT_TENT,
0 DAYUSE_CHILDS_DEF, 
0 DAYUSE_CHILDS_TENT,
0 BLOCK_ALL_DEF, 
0 BLOCK_ALL_TENT,
0 BLOCK_NOT_PICKUP_DEF,
0 BLOCK_NOT_PICKUP_TENT,
0 BLOCK_PICKUP_DEF,
0 BLOCK_PICKUP_TENT
from
V8_REP_WDAT_DATE_XCMA_CAD WDAT, V8_STAT_SHIS_XCMA_DAY_CAD SHIS
 where
 SHIS.WDAT_DATE =WDAT.WDAT_DATE AND
 SHIS.XCMA_ID =WDAT.XCMA_ID AND
 SHIS.YCAD_ID=WDAT.YCAD_ID
)
union all
(
select
S_POSDATE                                                                     WDAT_DATE, 
S_POSDATE                                                                     WDAT_DATE2, 
S_POSDATE                                                                     WDAT_DATE3, 
TO_CHAR(S_POSDATE,'yyyy_mm')                                     MONTHYEAR,
case when S_POSDATE>=(select wgbs_datevalue from wgbs) then 1 else 0 end      FUTURE, 
S_YCAD_ID                                                                       YCAD_ID,
S_XCMA_ID                                                                      XCMA_ID,
S_XCMM_ID                                                                      XCMM_ID,
sum(S_OCC_ROOMS_DEF)                                                OCC_ROOMS_DEF, 
sum(S_OCC_ROOMS_DEF_BOOKINGPOS)                           OCC_ROOMS_DEF_BOOKINGPOS,
sum(S_OCC_ROOMS_TENT)                                             OCC_ROOMS_TENT,
sum(S_OCC_ROOMS_TENT_BOOKINGPOS)                         OCC_ROOMS_TENT_BOOKINGPOS,
sum(S_ARR_ROOMS_DEF_TENT)                                                     ARR_ROOMS_DEF_TENT,
sum(S_ARR_ROOMS_DEF)                                                          ARR_ROOMS_DEF, 
sum(S_DEP_ROOMS_DEF_TENT)                                                     DEP_ROOMS_DEF_TENT,
sum(S_DEP_ROOMS_DEF)                                                          DEP_ROOMS_DEF,
sum(S_OCC_ADULTS_DEF)                                                         OCC_ADULTS_DEF,
sum(S_OCC_ADULTS_DEF_BOOKINGPOS)                                    OCC_ADULTS_DEF_BOOKINGPOS,
sum(S_OCC_ADULTS_TENT)                                                        OCC_ADULTS_TENT,
sum(S_OCC_ADULTS_TENT_BOOKINGPOS)                                    OCC_ADULTS_TENT_BOOKINGPOS,
sum(S_OCC_CHILDS_DEF)                                                         OCC_CHILDS_DEF,
sum(S_OCC_CHILDS_TENT)                                                        OCC_CHILDS_TENT, 
sum(S_DEF_ARR_ADULTS)                                                           DEF_ARR_ADULTS,
sum(S_TENT_ARR_ADULTS)                                                      TENT_ARR_ADULTS,
sum(S_DEF_ARR_KIDS)                                                             DEF_ARR_KIDS,
sum(S_TENT_ARR_KIDS)                                                           TENT_ARR_KIDS,
sum(S_DEF_ROOM_REV_GROSS)                                               DEF_ROOM_REV_GROSS,
sum(S_DEF_RM_REV_GROSS_BOOKINGPOS)                              DEF_RM_REV_GROSS_BOOKINGPOS,
sum(S_TENT_ROOM_REV_GROSS)                                           TENT_ROOM_REV_GROSS,
sum(S_TENT_RM_REV_GROSS_BOOKINGPOS)                       TENT_RM_REV_GROSS_BOOKINGPOS,
sum(S_DEF_ROOM_REV_NET)                                                 DEF_ROOM_REV_NET,
sum(S_DEF_RM_REV_NET_BOOKINGPOS)                              DEF_RM_REV_NET_BOOKINGPOS,
sum(S_TENT_ROOM_REV_NET)                                                TENT_ROOM_REV_NET,
sum(S_TENT_RM_REV_NET_BOOKINGPOS)                             TENT_RM_REV_NET_BOOKINGPOS,
sum(S_DEF_FB_REV_GROSS)                                                     DEF_FB_REV_GROSS,
sum(S_DEF_FB_REV_GROSS_BOOKINGPOS)                              DEF_FB_REV_GROSS_BOOKINGPOS,
sum(S_TENT_FB_REV_GROSS)                                                TENT_FB_REV_GROSS,
sum(S_TENT_FB_REV_GROSS_BOOKINGPOS)                             TENT_FB_REV_GROSS_BOOKINGPOS,
sum(S_DEF_FB_REV_NET)                                                       DEF_FB_REV_NET,
sum(S_DEF_FB_REV_NET_BOOKINGPOS)                                    DEF_FB_REV_NET_BOOKINGPOS,
sum(S_TENT_FB_REV_NET)                                                      TENT_FB_REV_NET,
sum(S_TENT_FB_REV_NET_BOOKINGPOS)                                  TENT_FB_REV_NET_BOOKINGPOS,
sum(S_DEF_OTHER_REV_GROSS)                                              DEF_OTHER_REV_GROSS,
sum(S_DEF_OTH_REV_GROSS_BOOKPOS)                             DEF_OTH_REV_GROSS_BOOKPOS,
sum(S_TENT_OTHER_REV_GROSS)                                             TENT_OTHER_REV_GROSS,
sum(S_TENT_OTH_REV_GROSS_BOOKPOS)                            TENT_OTH_REV_GROSS_BOOKPOS,
sum(S_DEF_OTHER_REV_NET)                                                    DEF_OTHER_REV_NET,
sum(S_DEF_OTH_REV_NET_BOOKPOS)                                   DEF_OTH_REV_NET_BOOKPOS,
sum(S_TENT_OTHER_REV_NET)                                                   TENT_OTHER_REV_NET,
sum(S_TENT_OTH_REV_NET_BOOKPOS)                                  TENT_OTH_REV_NET_BOOKPOS,
sum(S_DEF_REV_GROSS)                                                     DEF_REV_GROSS,
sum(S_DEF_REV_GROSS_BOOKINGPOS)                                  DEF_REV_GROSS_BOOKINGPOS,
sum(S_TENT_REV_GROSS)                                                 TENT_REV_GROSS,
sum(S_TENT_REV_GROSS_BOOKINGPOS)                             TENT_REV_GROSS_BOOKINGPOS,
sum(S_DEF_REV_NET)                                                       DEF_REV_NET,
sum(S_DEF_REV_NET_BOOKINGPOS)                                   DEF_REV_NET_BOOKINGPOS,
sum(S_TENT_REV_NET)                                                      TENT_REV_NET,
sum(S_TENT_REV_NET_BOOKINGPOS)                                  TENT_REV_NET_BOOKINGPOS,
sum(S_DAYUSE_RMS_DEF)                                                       DAYUSE_RMS_DEF, 
sum(S_DAYUSE_RMS_TENT)                                                       DAYUSE_RMS_TENT,  
sum(S_ARR_DAYUSE_RMS_DEF_TENT)                                       ARR_DAYUSE_RMS_DEF_TENT, 
sum(S_ARR_DAYUSE_RMS_DEF)                                               ARR_DAYUSE_RMS_DEF ,
sum(S_DEP_DAYUSE_RMS_DEF_TENT)                                       DEP_DAYUSE_RMS_DEF_TENT,  
sum(S_DEP_DAYUSE_RMS_DEF)                                               DEP_DAYUSE_RMS_DEF,
sum(S_DAYUSE_ADLT_DEF)                                                      DAYUSE_ADLT_DEF , 
sum(S_DAYUSE_ADLT_TENT)                                                 DAYUSE_ADLT_TENT,
sum(S_DAYUSE_CHILDS_DEF)                                                 DAYUSE_CHILDS_DEF , 
sum(S_DAYUSE_CHILDS_TENT)                                              DAYUSE_CHILDS_TENT,
sum(S_BLOCK_ALL_DEF)                                                                BLOCK_ALL_DEF, 
sum(S_BLOCK_ALL_TENT)                                                               BLOCK_ALL_TENT,
sum(S_BLOCK_NOT_PICKUP_DEF)                                                 BLOCK_NOT_PICKUP_DEF,
sum(S_BLOCK_NOT_PICKUP_TENT)                                               BLOCK_NOT_PICKUP_TENT,
sum(S_BLOCK_PICKUP_DEF)                                                        BLOCK_PICKUP_DEF,
sum(S_BLOCK_PICKUP_TENT)                                                        BLOCK_PICKUP_TENT
from
(
select
WDAT.WDAT_DATE                                                               S_POSDATE,
WDAT.YCAD_ID                                                                  S_YCAD_ID,
WDAT.XCMA_ID                                                                 S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                                       S_XCMM_ID,
nvl(S_REP_YBLD_OCC_XCMA_CAD.S_DEFNOOFROOMS,0)+nvl(S_REP_YDET_OCC_WB_XCMA_CAD.S_DEFNOOFROOMS,0)                                                                                                                                                                                 S_OCC_ROOMS_DEF,
nvl(S_REP_YBLD_OCC_XCMA_CAD.S_DEFNOOFROOMS,0)+nvl(S_REP_YDET_OCC_WB_XCMA_CAD.S_DEFNOOFROOMS,0)+nvl(S_REP_YBLD_OCC_XCMA_CAD.S_DEFNOOFROOMSBOOKINGPOSAVAIL,0)                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS, 
nvl(S_REP_YBLD_OCC_XCMA_CAD.S_TENTNOOFROOMS,0)+nvl(S_REP_YDET_OCC_WB_XCMA_CAD.S_TENTNOOFROOMS,0)-nvl(S_REP_YDET_OCC_WB_XCMA_CAD.S_TENTBLOCKDEFRESROOM,0)                                                                            S_OCC_ROOMS_TENT,
nvl(S_REP_YBLD_OCC_XCMA_CAD.S_TENTNOOFROOMS,0)+nvl(S_REP_YDET_OCC_WB_XCMA_CAD.S_TENTNOOFROOMS,0)+nvl(S_REP_YBLD_OCC_XCMA_CAD.S_TENTNOOFROOMSBOOKINGPOSAVAIL,0)-nvl(S_REP_YDET_OCC_WB_XCMA_CAD.S_TENTBLOCKDEFRESROOM,0)                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
nvl(S_REP_YDET_OCC_WB_XCMA_CAD.S_DEFNOOFROOMSDAYUSE,0)                                  S_DAYUSE_RMS_DEF,   
nvl(S_REP_YDET_OCC_WB_XCMA_CAD.S_TENTNOOFROOMSDAYUSE,0)                                 S_DAYUSE_RMS_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
nvl(S_REP_YBLD_OCC_XCMA_CAD.S_DEFNOOFROOMS,0)        S_BLOCK_ALL_DEF,
nvl(S_REP_YBLD_OCC_XCMA_CAD.S_TENTNOOFROOMS,0)                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
 from 
 V8_REP_WDAT_DATE_XCMA_CAD wdat,
( select 
V8_REP_YBLD_OCC_XCMA_CAD.YBLD_DATE S_YBLD_DATE,
V8_REP_YBLD_OCC_XCMA_CAD.YBLH_XCMA_ID S_YCAD_ID,
V8_REP_YBLD_OCC_XCMA_CAD.YBLH_XCMA_ID S_XCMA_ID,
sum(V8_REP_YBLD_OCC_XCMA_CAD.DEFNOOFROOMS) S_DEFNOOFROOMS, 
sum(V8_REP_YBLD_OCC_XCMA_CAD.DEFNOOFROOMSBOOKINGPOSAVAIL) S_DEFNOOFROOMSBOOKINGPOSAVAIL,
sum(V8_REP_YBLD_OCC_XCMA_CAD.TENTNOOFROOMS) S_TENTNOOFROOMS,
sum(V8_REP_YBLD_OCC_XCMA_CAD.TENTNOOFROOMSBOOKINGPOSAVAIL) S_TENTNOOFROOMSBOOKINGPOSAVAIL
 from V8_REP_YBLD_OCC_XCMA_CAD
 group by V8_REP_YBLD_OCC_XCMA_CAD.YBLD_DATE, V8_REP_YBLD_OCC_XCMA_CAD.YCAD_ID,V8_REP_YBLD_OCC_XCMA_CAD.YBLH_XCMA_ID) S_REP_YBLD_OCC_XCMA_CAD,
 ( select 
V8_REP_YDET_OCC_WB_XCMA_CAD.YDET_DATE S_YDET_DATE,
V8_REP_YDET_OCC_WB_XCMA_CAD.YCAD_ID S_YCAD_ID,
V8_REP_YDET_OCC_WB_XCMA_CAD.YDET_XCMA_ID S_XCMA_ID,
sum(V8_REP_YDET_OCC_WB_XCMA_CAD.DEFNOOFROOMS) S_DEFNOOFROOMS, 
sum(V8_REP_YDET_OCC_WB_XCMA_CAD.DEFNOOFROOMSDAYUSE) S_DEFNOOFROOMSDAYUSE,
sum(V8_REP_YDET_OCC_WB_XCMA_CAD.TENTNOOFROOMS) S_TENTNOOFROOMS,
sum(V8_REP_YDET_OCC_WB_XCMA_CAD.TENTNOOFROOMSDAYUSE) S_TENTNOOFROOMSDAYUSE,
sum(V8_REP_YDET_OCC_WB_XCMA_CAD.TENTBLOCKDEFRESROOM) S_TENTBLOCKDEFRESROOM
 from V8_REP_YDET_OCC_WB_XCMA_CAD
 group by V8_REP_YDET_OCC_WB_XCMA_CAD.YDET_DATE,V8_REP_YDET_OCC_WB_XCMA_CAD.YCAD_ID,V8_REP_YDET_OCC_WB_XCMA_CAD.YDET_XCMA_ID) S_REP_YDET_OCC_WB_XCMA_CAD
 where
 WDAT.WDAT_DATE=S_REP_YBLD_OCC_XCMA_CAD.S_YBLD_DATE(+) and
 WDAT.YCAD_ID=S_REP_YBLD_OCC_XCMA_CAD.S_YCAD_ID(+) and
 WDAT.XCMA_ID = S_REP_YBLD_OCC_XCMA_CAD.S_XCMA_ID(+) and
 WDAT.WDAT_DATE=S_REP_YDET_OCC_WB_XCMA_CAD.S_YDET_DATE(+) and
 WDAT.YCAD_ID=S_REP_YDET_OCC_WB_XCMA_CAD.S_YCAD_ID(+) and
 WDAT.XCMA_ID = S_REP_YDET_OCC_WB_XCMA_CAD.S_XCMA_ID(+)
union all
select 
V8_REP_ARR_DEP_COMB_XCMA_CAD.WDAT_DATE                                     S_POSDATE,
V8_REP_ARR_DEP_COMB_XCMA_CAD.YCAD_ID                                         S_YCAD_ID,
V8_REP_ARR_DEP_COMB_XCMA_CAD.XCMA_ID                                       S_XCMA_ID,
V8_REP_ARR_DEP_COMB_XCMA_CAD.XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
V8_REP_ARR_DEP_COMB_XCMA_CAD.ARREXPROOM                                    S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,
V8_REP_ARR_DEP_COMB_XCMA_CAD.DEPEXPROOM                                    S_DEP_ROOMS_DEF_TENT, 
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
V8_REP_ARR_DEP_COMB_XCMA_CAD.ARREXPROOMDAYUSE                                                                S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
V8_REP_ARR_DEP_COMB_XCMA_CAD.DEPEXPROOMDAYUSE                                                                S_DEP_DAYUSE_RMS_DEF_TENT,    
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from V8_REP_ARR_DEP_COMB_XCMA_CAD
union all
select 
V8_REP_HS_ARR_ALLRMS_XCMA_CAD.WDAT_DATE                                          S_POSDATE,
V8_REP_HS_ARR_ALLRMS_XCMA_CAD.YCAD_ID                                             S_YCAD_ID,
V8_REP_HS_ARR_ALLRMS_XCMA_CAD.XCMA_ID                                            S_XCMA_ID,
V8_REP_HS_ARR_ALLRMS_XCMA_CAD.XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
V8_REP_HS_ARR_ALLRMS_XCMA_CAD.DEFEXPROOM                                         S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
V8_REP_HS_ARR_ALLRMS_XCMA_CAD.DEFEXPROOMDAYUSE                                                                            S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from V8_REP_HS_ARR_ALLRMS_XCMA_CAD
union all
select
V8_REP_HS_DEP_ALLRMS_XCMA_CAD.WDAT_DATE                                          S_POSDATE,
V8_REP_HS_DEP_ALLRMS_XCMA_CAD.YCAD_ID                                             S_YCAD_ID,
V8_REP_HS_DEP_ALLRMS_XCMA_CAD.XCMA_ID                                            S_XCMA_ID,
V8_REP_HS_DEP_ALLRMS_XCMA_CAD.XCMM_ID                                                    S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
V8_REP_HS_DEP_ALLRMS_XCMA_CAD.DEFDEPROOM                                         S_DEP_ROOMS_DEF,
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
V8_REP_HS_DEP_ALLRMS_XCMA_CAD.DEFDEPROOMDAYUSE                                                                            S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from V8_REP_HS_DEP_ALLRMS_XCMA_CAD
union all
select
WDAT.WDAT_DATE                                                               S_POSDATE,
WDAT.YCAD_ID                                                                S_YCAD_ID,
WDAT.XCMA_ID                                                                 S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF,
nvl(S_REP_YDET_ADULT_WB_XCMA_CAD.S_DEFADULTNO,0)-nvl(S_REP_YDET_ADULT_WB_XCMA_CAD.S_DEFBLOCKSUBSTRACT,0)+nvl(S_REP_YBLD_OCC_XCMA_CAD.S_DEFNOOFADULTS,0)    S_OCC_ADULTS_DEF, 
nvl(S_REP_YBLD_OCC_XCMA_CAD.S_DEFNOOFADULTSBOOKPOSAVAIL,0)+nvl(S_REP_YDET_ADULT_WB_XCMA_CAD.S_DEFADULTNO,0)                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
nvl(S_REP_YDET_ADULT_WB_XCMA_CAD.S_TENTADULTNO,0)-nvl(S_REP_YDET_ADULT_WB_XCMA_CAD.S_TENTBLOCKSUBSTRACT,0)+nvl(S_REP_YBLD_OCC_XCMA_CAD.S_TENTNOOFADULTS,0) S_OCC_ADULTS_TENT,
nvl(S_REP_YBLD_OCC_XCMA_CAD.S_TENTNOOFADULTSBOOKPOSAVAIL,0)+nvl(S_REP_YDET_ADULT_WB_XCMA_CAD.S_TENTADULTNO,0)                                                                           S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
nvl(S_REP_YDET_ADULT_WB_XCMA_CAD.S_DEFADULTNODAYUSE,0)                                                                            S_DAYUSE_ADLT_DEF, 
nvl(S_REP_YDET_ADULT_WB_XCMA_CAD.S_TENTADULTNODAYUSE,0)                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from 
V8_REP_WDAT_DATE_XCMA_CAD wdat,
( select 
V8_REP_YBLD_OCC_XCMA_CAD.YBLD_DATE S_YBLD_DATE,
V8_REP_YBLD_OCC_XCMA_CAD.YCAD_ID S_YCAD_ID,
V8_REP_YBLD_OCC_XCMA_CAD.YBLH_XCMA_ID S_XCMA_ID,
sum(V8_REP_YBLD_OCC_XCMA_CAD.DEFNOOFADULTS) S_DEFNOOFADULTS, 
sum(V8_REP_YBLD_OCC_XCMA_CAD.DEFNOOFADULTSBOOKINGPOSAVAIL) S_DEFNOOFADULTSBOOKPOSAVAIL,
sum(V8_REP_YBLD_OCC_XCMA_CAD.TENTNOOFADULTS) S_TENTNOOFADULTS,
sum(V8_REP_YBLD_OCC_XCMA_CAD.TENTNOOFADULTSBOOKINGPOSAVAIL) S_TENTNOOFADULTSBOOKPOSAVAIL
 from V8_REP_YBLD_OCC_XCMA_CAD
 group by V8_REP_YBLD_OCC_XCMA_CAD.YBLD_DATE, V8_REP_YBLD_OCC_XCMA_CAD.YCAD_ID, V8_REP_YBLD_OCC_XCMA_CAD.YBLH_XCMA_ID) S_REP_YBLD_OCC_XCMA_CAD,
 ( select 
V8_REP_YDET_ADULT_WB_XCMA_CAD.YDET_DATE S_YDET_DATE,
V8_REP_YDET_ADULT_WB_XCMA_CAD.YCAD_ID S_YCAD_ID,
V8_REP_YDET_ADULT_WB_XCMA_CAD.YDET_XCMA_ID S_XCMA_ID,
sum(V8_REP_YDET_ADULT_WB_XCMA_CAD.DEFADULTNO) S_DEFADULTNO,
sum(V8_REP_YDET_ADULT_WB_XCMA_CAD.DEFADULTNODAYUSE) S_DEFADULTNODAYUSE,
sum(V8_REP_YDET_ADULT_WB_XCMA_CAD.TENTADULTNO) S_TENTADULTNO,
sum(V8_REP_YDET_ADULT_WB_XCMA_CAD.TENTADULTNODAYUSE) S_TENTADULTNODAYUSE,
sum(V8_REP_YDET_ADULT_WB_XCMA_CAD.DEFBLOCKSUBSTRACT) S_DEFBLOCKSUBSTRACT,
sum(V8_REP_YDET_ADULT_WB_XCMA_CAD.TENTBLOCKSUBSTRACT) S_TENTBLOCKSUBSTRACT
 from V8_REP_YDET_ADULT_WB_XCMA_CAD
 group by V8_REP_YDET_ADULT_WB_XCMA_CAD.YDET_DATE, V8_REP_YDET_ADULT_WB_XCMA_CAD.YCAD_ID, V8_REP_YDET_ADULT_WB_XCMA_CAD.YDET_XCMA_ID ) S_REP_YDET_ADULT_WB_XCMA_CAD
 where
 WDAT.WDAT_DATE=S_REP_YBLD_OCC_XCMA_CAD.S_YBLD_DATE(+) and
 WDAT.XCMA_ID = S_REP_YBLD_OCC_XCMA_CAD.S_XCMA_ID(+) and
 WDAT.YCAD_ID = S_REP_YBLD_OCC_XCMA_CAD.S_YCAD_ID(+) and
 WDAT.WDAT_DATE=S_REP_YDET_ADULT_WB_XCMA_CAD.S_YDET_DATE(+) and
 WDAT.XCMA_ID = S_REP_YDET_ADULT_WB_XCMA_CAD.S_XCMA_ID(+) and
 WDAT.YCAD_ID = S_REP_YDET_ADULT_WB_XCMA_CAD.S_YCAD_ID(+)
union all
select
WDAT.WDAT_DATE                                                             S_POSDATE,
WDAT.YCAD_ID                                                S_YCAD_ID,
WDAT.XCMA_ID                                               S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                   S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
sum(decode(YRES.YRES_RESSTATUS,1,YRGL.YRGL_NUMBER*YDET.YDET_NOOFROOMS,0))    S_OCC_CHILDS_DEF,
sum(decode(YRES.YRES_RESSTATUS,0,YRGL.YRGL_NUMBER*YDET.YDET_NOOFROOMS,0))    S_OCC_CHILDS_TENT,
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
YDET,YRGL,YRES,XCAC, V8_REP_WDAT_DATE_XCMA_CAD WDAT, YCAT
WHERE YRGL.yrgl_ydet_id=YDET.ydet_id  AND 
YRES.yres_id=YDET.ydet_yres_id AND 
XCAC.xcac_id=yrgl_xcac_id AND 
YDET.YDET_DATE=WDAT.WDAT_DATE AND 
YDET.YDET_XCMA_ID=WDAT.XCMA_ID AND
YDET.YDET_YCAT_ID=YCAT.YCAT_ID AND
YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID=WDAT.YCAD_ID
GROUP BY WDAT.WDAT_DATE,WDAT.YCAD_ID, WDAT.XCMA_ID, WDAT.XCMA_XCMM_ID
union all
select 
WDAT.WDAT_DATE                                                             S_POSDATE,
WDAT.YCAD_ID                                                S_YCAD_ID,
WDAT.XCMA_ID                                               S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                   S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF,
0                                                                             S_OCC_CHILDS_TENT,
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
sum(decode(YRES.YRES_RESSTATUS,1,YRGL.YRGL_NUMBER*YDET.YDET_NOOFROOMS,0))                                                                                S_DAYUSE_CHILDS_DEF, 
sum(decode(YRES.YRES_RESSTATUS,0,YRGL.YRGL_NUMBER*YDET.YDET_NOOFROOMS,0))                                                                                S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
YDET,YRGL,YRES,XCAC, V8_REP_WDAT_DATE_XCMA_CAD WDAT, YCAT
WHERE YRGL.yrgl_ydet_id=YDET.ydet_id  AND 
YRES.yres_id=YDET.ydet_yres_id AND 
XCAC.xcac_id=yrgl_xcac_id AND 
YDET.YDET_DATE=WDAT.WDAT_DATE AND 
YRES.YRES_EXPARRTIME = YRES.YRES_EXPDEPTIME AND
YDET.YDET_XCMA_ID=WDAT.XCMA_ID AND
YDET.YDET_YCAT_ID=YCAT.YCAT_ID AND
YCAT.YCAT_SUM_ROOMTYPE_YCAD_ID=WDAT.YCAD_ID
GROUP BY WDAT.WDAT_DATE, WDAT.YCAD_ID,WDAT.XCMA_ID, WDAT.XCMA_XCMM_ID
union all 
select
V8_REP_HS_ARR_ALLADL_XCMA_CAD.WDAT_DATE                                                             S_POSDATE,
V8_REP_HS_ARR_ALLADL_XCMA_CAD.YCAD_ID                                                S_YCAD_ID,
V8_REP_HS_ARR_ALLADL_XCMA_CAD.XCMA_ID                                               S_XCMA_ID,
V8_REP_HS_ARR_ALLADL_XCMA_CAD.XCMM_ID                                   S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
V8_REP_HS_ARR_ALLADL_XCMA_CAD.defexpadult                                                                             S_DEF_ARR_ADULTS,
V8_REP_HS_ARR_ALLADL_XCMA_CAD.tentexpadult                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_HS_ARR_ALLADL_XCMA_CAD
union all
select
V8_REP_HS_ARR_ALLCHI_XCMA_CAD.WDAT_DATE                                                             S_POSDATE,
V8_REP_HS_ARR_ALLCHI_XCMA_CAD.YCAD_ID                            S_YCAD_ID,
V8_REP_HS_ARR_ALLCHI_XCMA_CAD.XCMA_ID                                               S_XCMA_ID,
V8_REP_HS_ARR_ALLCHI_XCMA_CAD.XCMM_ID                         S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
V8_REP_HS_ARR_ALLCHI_XCMA_CAD.DEFARRCHILD        S_DEF_ARR_KIDS,
V8_REP_HS_ARR_ALLCHI_XCMA_CAD.TENTARRCHILD      S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_HS_ARR_ALLCHI_XCMA_CAD
union all
select 
V.YPOS_DATE                                                                  S_POSDATE,
V.YCAD_ID                                                                       S_YCAD_ID,
V.XCMA_ID                                                                    S_XCMA_ID,
V.XCMM_ID                                                               S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
V.DEF_REV_GROSS                                                   S_DEV_ROOM_REV_GROSS,
V.DEF_REV_GROSS_BOOKINGPOS                               S_DEF_RM_REV_GROSS_BOOKINGPOS,
V.TENT_REV_GROSS                                                 S_TENT_ROOM_REV_GROSS,
V.TENT_REV_GROSS_BOOKINGPOS                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
V.DEF_REV_NET                                                       S_DEF_ROOM_REV_NET,
V.DEF_REV_NET_BOOKINGPOS                                  S_DEF_RM_REV_NET_BOOKINGPOS,
V.TENT_REV_NET                                                     S_TENT_ROOM_REV_NET,
V.TENT_REV_NET_BOOKINGPOS                                S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YPOS_FC_XCMA_STAT1_CAD V 
union all 
select 
V.YPOS_DATE                                                                  S_POSDATE,
V.YCAD_ID                                                                       S_YCAD_ID,
V.XCMA_ID                                                                    S_XCMA_ID,
V.XCMM_ID                                                               S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
V.DEF_REV_GROSS                                                   S_DEV_FB_REV_GROSS,
V.DEF_REV_GROSS_BOOKINGPOS                               S_DEF_FB_REV_GROSS_BOOKINGPOS,
V.TENT_REV_GROSS                                                S_TENT_FB_REV_GROSS,
V.TENT_REV_GROSS_BOOKINGPOS                            S_TENT_FB_REV_GROSS_BOOKINGPOS,
V.DEF_REV_NET                                                        S_DEV_FB_REV_NET,
V.DEF_REV_NET_BOOKINGPOS                              S_DEF_FB_REV_NET_BOOKINGPOS,
V.TENT_REV_NET                                                     S_TENT_FB_REV_NET,
V.TENT_REV_NET_BOOKINGPOS                               S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YPOS_FC_XCMA_STAT2_CAD V 
union all
select 
V.YPOS_DATE                                                                  S_POSDATE,
V.YCAD_ID                                                                       S_YCAD_ID,
V.XCMA_ID                                                                    S_XCMA_ID,
V.XCMM_ID                                                               S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
V.DEF_REV_GROSS                                                    S_DEF_OTHER_REV_GROSS,
V.DEF_REV_GROSS_BOOKINGPOS                              S_DEF_OTH_REV_GROSS_BOOKPOS,
V.TENT_REV_GROSS                                                S_TENT_OTHER_REV_GROSS,
V.TENT_REV_GROSS_BOOKINGPOS                            S_TENT_OTH_REV_GROSS_BOOKPOS,
V.DEF_REV_NET                                                        S_DEF_OTHER_REV_NET,
V.DEF_REV_NET_BOOKINGPOS                              S_DEF_OTH_REV_NET_BOOKPOS,
V.TENT_REV_NET                                                     S_TENT_OTHER_REV_NET,
V.TENT_REV_NET_BOOKINGPOS                                S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YPOS_FC_XCMA_ST345_CAD V
union all
select 
V.YPOS_DATE                                                                  S_POSDATE,
V.YCAD_ID                                                                       S_YCAD_ID,
V.XCMA_ID                                                                    S_XCMA_ID,
V.XCMM_ID                                                               S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                              S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
V.DEF_REV_GROSS                                                 S_DEF_REV_GROSS,
V.DEF_REV_GROSS_BOOKINGPOS                            S_DEF_REV_GROSS_BOOKINGPOS,
V.TENT_REV_GROSS                                               S_TENT_REV_GROSS,
V.TENT_REV_GROSS_BOOKINGPOS                          S_TENT_REV_GROSS_BOOKINGPOS,
V.DEF_REV_NET                                                      S_DEF_REV_NET,
V.DEF_REV_NET_BOOKINGPOS                                 S_DEF_REV_NET_BOOKINGPOS,
V.TENT_REV_NET                                                   S_TENT_REV_NET,
V.TENT_REV_NET_BOOKINGPOS                              S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YPOS_FC_XCMA_CAD V
union all
select 
WDAT.WDAT_DATE                                                   S_POSDATE,
WDAT.YCAD_ID                                                        S_YCAD_ID,
WDAT.XCMA_ID                                                         S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
V8_REP_YBLD_NO_PICKUP_XCMA_CAD.DEFNOOFROOMS     S_BLOCK_NOT_PICKUP_DEF,
V8_REP_YBLD_NO_PICKUP_XCMA_CAD.TENTNOOFROOMS   S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED
from
V8_REP_YBLD_NO_PICKUP_XCMA_CAD,
V8_REP_WDAT_DATE_XCMA_CAD WDAT
where
WDAT.WDAT_DATE=V8_REP_YBLD_NO_PICKUP_XCMA_CAD.YBLD_DATE(+) and
WDAT.XCMA_ID=V8_REP_YBLD_NO_PICKUP_XCMA_CAD.XCMA_ID(+) and
WDAT.YCAD_ID=V8_REP_YBLD_NO_PICKUP_XCMA_CAD.YCAD_ID(+)
union all
select
WDAT.WDAT_DATE                                                   S_POSDATE,
WDAT.YCAD_ID                                                        S_YCAD_ID,
WDAT.XCMA_ID                                                         S_XCMA_ID,
WDAT.XCMA_XCMM_ID                                           S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
V8_REP_YBLD_PICKUP_XCMA_CAD.DEFNOOFROOMS            S_BLOCK_PICKUP_DEF,
V8_REP_YBLD_PICKUP_XCMA_CAD.TENTNOOFROOMS          S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED 
from
V8_REP_YBLD_PICKUP_XCMA_CAD,
V8_REP_WDAT_DATE_XCMA_CAD WDAT
where
WDAT.WDAT_DATE=V8_REP_YBLD_PICKUP_XCMA_CAD.YBLD_DATE(+) and
WDAT.XCMA_ID=V8_REP_YBLD_PICKUP_XCMA_CAD.XCMA_ID(+) and
WDAT.YCAD_ID=V8_REP_YBLD_PICKUP_XCMA_CAD.YCAD_ID(+)
union all
select
WDAT_DATE                                                          S_POSDATE,
YCAD_ID                                                        S_YCAD_ID,
XCMA_ID                                                                S_XCMA_ID,
XCMA_XCMM_ID                                                                 S_XCMM_ID,
0                                                                            S_OCC_ROOMS_DEF, 
0                                                                             S_OCC_ROOMS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ROOMS_TENT,
0                                                                             S_OCC_ROOMS_TENT_BOOKINGPOS,
0                                                                             S_ARR_ROOMS_DEF_TENT,
0                                                                             S_ARR_ROOMS_DEF,  
0                                                                            S_DEP_ROOMS_DEF_TENT,
0                                                                            S_DEP_ROOMS_DEF, 
0                                                                             S_OCC_ADULTS_DEF, 
0                                                                             S_OCC_ADULTS_DEF_BOOKINGPOS,
0                                                                             S_OCC_ADULTS_TENT,
0                                                                             S_OCC_ADULTS_TENT_BOOKINGPOS,
0                                                                             S_OCC_CHILDS_DEF, 
0                                                                             S_OCC_CHILDS_TENT, 
0                                                                             S_DEF_ARR_ADULTS,
0                                                                             S_TENT_ARR_ADULTS,
0                                                                             S_DEF_ARR_KIDS,
0                                                                             S_TENT_ARR_KIDS,
0                                                                            S_DEF_ROOM_REV_GROSS,
0                                                                             S_DEF_RM_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_GROSS,
0                                                                             S_TENT_RM_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_ROOM_REV_NET,
0                                                                            S_DEF_RM_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_ROOM_REV_NET,
0                                                                             S_TENT_RM_REV_NET_BOOKINGPOS,
0                                                                             S_DEF_FB_REV_GROSS,
0                                                                             S_DEF_FB_REV_GROSS_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_GROSS,
0                                                                             S_TENT_FB_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_FB_REV_NET,
0                                                                             S_DEF_FB_REV_NET_BOOKINGPOS,
0                                                                             S_TENT_FB_REV_NET,
0                                                                             S_TENT_FB_REV_NET_BOOKINGPOS,
0                                                                            S_DEF_OTHER_REV_GROSS,
0                                                                             S_DEF_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_TENT_OTHER_REV_GROSS,
0                                                                             S_TENT_OTH_REV_GROSS_BOOKPOS,
0                                                                             S_DEF_OTHER_REV_NET,
0                                                                             S_DEF_OTH_REV_NET_BOOKPOS,
0                                                                            S_TENT_OTHER_REV_NET,
0                                                                             S_TENT_OTH_REV_NET_BOOKPOS, 
0                                                                            S_DEF_REV_GROSS,
0                                                                            S_DEF_REV_GROSS_BOOKINGPOS,
0                                                                            S_TENT_REV_GROSS,
0                                                                            S_TENT_REV_GROSS_BOOKINGPOS,
0                                                                            S_DEF_REV_NET,
0                                                                            S_DEF_REV_NET_BOOKINGPOS,
0                                                                            S_TENT_REV_NET,
0                                                                            S_TENT_REV_NET_BOOKINGPOS,
0                                                                           S_DAYUSE_RMS_DEF, 
0                                                                           S_DAYUSE_RMS_TENT,  
0                                                                           S_ARR_DAYUSE_RMS_DEF_TENT, 
0                                                                           S_ARR_DAYUSE_RMS_DEF,
0                                                                           S_DEP_DAYUSE_RMS_DEF_TENT,  
0                                                                           S_DEP_DAYUSE_RMS_DEF,
0                                                                           S_DAYUSE_ADLT_DEF, 
0                                                                           S_DAYUSE_ADLT_TENT,
0                                                                           S_DAYUSE_CHILDS_DEF, 
0                                                                           S_DAYUSE_CHILDS_TENT,
0                                                                           S_BLOCK_ALL_DEF,
0                                                                           S_BLOCK_ALL_TENT,
0                                                                           S_BLOCK_NOT_PICKUP_DEF,
0                                                                           S_BLOCK_NOT_PICKUP_TENT,
0                                                                           S_BLOCK_PICKUP_DEF,
0                                                                           S_BLOCK_PICKUP_TENT,
0                                                                           S_NOT_USED 
from
V8_REP_WDAT_DATE_XCMA_CAD WDAT
)
where not exists (select 1 from V8_STAT_SHIS_XCMA_DAY_CAD SHIS where SHIS.WDAT_DATE=S_POSDATE and SHIS.YCAD_ID=S_YCAD_ID and SHIS.XCMA_ID=S_XCMA_ID) 
group by S_POSDATE, S_YCAD_ID, S_XCMA_ID, S_XCMM_ID
) order by wdat_date, YCAD_ID,xcma_id;

CREATE OR REPLACE VIEW V8_WEBAPI_ROOMACTUALS
AS 
select
YRMS.YRMS_ID
,YRMS.YRMS_WALKORDER SORT_ORDER
,YRMS.YRMS_SHORTDESC
,YRMS.YRMS_FLOOR
,YCAT.YCAT_SHORTDESC
,YRMS.YRMS_NOOFPERSONS
,YHKS.YHKS_SHORTDESC
,YHKS.YHKS_CLEAN
,YRMS.YRMS_DEFAULTCREDITS
,YRMS.YRMS_DEPARTURECREDITS
,YRMS.YRMS_VALIDFROM
,YRMS.YRMS_VALIDUNTIL
,YCAT.YCAT_LONGDESC
,YRMS.YRMS_LONGDESC
,YHKS.YHKS_LONGDESC
,ARES.ARESID YRES_ID
,YRMS.YRMS_GUESTSERVICE_STATUS GUESTSTATUS
,TO_CHAR(YRMS.YRMS_HSK_OCCUPIED) HOUSEKEEPINGSTATUS
,DECODE(DECODE(ARES.ACALCSTATUS,3,1,4,1,8,1,0),1,1,DECODE(NRES.NCALCSTATUS,2,1,8,1,0)) FRONTOFFICESTATUS
,ARES.AGUESTNAME GUESTNAME
,ARES.ACMSID GUESTID
,NRES.NGUESTNAME NEXTGUESTNAME
,NRES.NCMSID NEXTGUESTID
,NRES.NRESID NEXTYRESID
,(SELECT yhac_comment FROM yhrl, yhac, fideliodate WHERE yhrl_date=wgbs_datevalue and yhrl_yrms_id=yrms.yrms_id and yhrl_yhac_id=yhac_id) MaidNotes
,(case when exists (select 1 from xpal where xpal_xpac_id=11 and xpal_xcms_id=DECODE(ARES.ACMSID,null,NRES.NCMSID)) then 1 else 0 end) IS_VIP
--,(case when exists (select 1 from yque where yque_yres_id=NRES.NRESID) then 1 else 0 end) IN_QUEUE
,(select YQUE_Q_DATE from yque where yque_yres_id=NRES.NRESID) QUEUE_date
,(select yrsc_id from yrst, yrsc, fideliodate f where  yrst_yrms_id=yrms.yrms_id and yrst_fromtime<=f.wgbs_datevalue and yrst_untiltime>f.wgbs_datevalue and yrst_yrsc_id=yrsc_id and rownum=1) SERVICESTATUS
,0 RESCOUNT
,ARES.AEXPARRTIME ARRIVAL
,ARES.AEXPDEPTIME DEPARTURE
,NRES.NEXPARRHOUR EXPARRHOURNEXTGUESTTODAY
,ARES.AEXPDEPHOUR EXPDEPHOURCURRENTGUEST
,DECODE(NRES.NRESID,null,0,1) IS_ARRIVAL
,NVL(DECODE(ARES.ACALCSTATUS,4,1,5.1,0),0) IS_DEPARTURE
,ARES.AADULTNO ADULTS
,ARES.AKIDS CHILDCOUNT
,(case when exists (select 1 from ydet,yres where nvl(yres.yres_current_ydet_id,yres.yres_last_ydet_id)=ydet.ydet_id and ydet.ydet_yrms_id=yrms.yrms_id and yres.yres_calcstatus=3) then 1 else 0 end) IS_STAYOVER
,(case when exists (select 1 from ydet,yres where nvl(yres_current_ydet_id,yres_last_ydet_id)=ydet_id and ydet_yrms_id=yrms.yrms_id and yres_calcstatus in (15,8,7)) then 1 else 0 end) IS_DAYUSE
,(select count(yamn_id) Linen  from yhra,yamn, yhrl, fideliodate where yhra_yamn_id=yamn_id and (yamn_role=1) and yhra_yhrl_id=yhrl_id and yhrl_yrms_id=yrms.yrms_id and yhrl_date=wgbs_datevalue) LINEN
,(select count(yamn_id) Towel from yhra,yamn, yhrl, fideliodate where yhra_yamn_id=yamn_id and (yamn_role=2) and yhra_yhrl_id=yhrl_id and yhrl_yrms_id=yrms.yrms_id and yhrl_date=wgbs_datevalue) TOWEL
,(SELECT count(wact_id) FROM wact, waty WHERE  wact_waty_id = waty_id AND WACT_COMPLTIME IS NULL  AND wact_place_type=1 and wact_place_id=YRMS.YRMS_id ) MAINTENANCE_CNT
,(select nvl(yhat_name,'')  from yhrl, yhat, yhhc where  yhrl_yhat_id=yhat_id and yhat_yhhc_id=yhhc_id and yhrl_date=(select wgbs_datevalue from fideliodate)  and yhrl_yrms_id=yrms.yrms_id and yhhc_role=0) Maid_Name 
,(select nvl(yhat_name,'')  from yhrl, yhat, yhhc where  yhrl_yhat_id=yhat_id and yhat_yhhc_id=yhhc_id and yhrl_date=(select wgbs_datevalue from fideliodate)  and yhrl_yrms_id=yrms.yrms_id and yhhc_role=1) Manager_Name 
, (select yhat_xced_id  from yhrl, yhat, yhhc where  yhrl_yhat_id=yhat_id and yhat_yhhc_id=yhhc_id and yhrl_date=(select wgbs_datevalue from fideliodate)  and yhrl_yrms_id=yrms.yrms_id and yhhc_role=0) Maid_EmployeeId 
, (select yhat_xced_id  from yhrl, yhat, yhhc where  yhrl_yhat_id=yhat_id and yhat_yhhc_id=yhhc_id and yhrl_date=(select wgbs_datevalue from fideliodate)  and yhrl_yrms_id=yrms.yrms_id and yhhc_role=1) Manager_EmployeeId
, (case when exists (select 1 from xcnc, xcno where xcnc_tablelinkedto=0 and xcnc_id=xcno_xcnc_id and xcno_tablelinkedto='XCMS' and xcno_table_id=ARES.ACMSID) then 1 else 0 end)   guestNotesExists,
YHKS_id,
ycat_id
from
yrms, ycat, yhks,
(--Current Guest
--no sharer
select 
RA.YRES_ID ARESID,
DA.YDET_ADULTNO AADULTNO,
YRMS.YRMS_ID ARMSID,
RA.YRES_CALCSTATUS ACALCSTATUS,
RA.YRES_EXPARRTIME AEXPARRTIME,
RA.YRES_ACTARRTIME AACTARRTIME,
RA.YRES_EXPDEPTIME AEXPDEPTIME,
RA.YRES_ACTDEPTIME AACTDEPTIME,
RA.YRES_EXPARRHOUR AEXPARRHOUR,
RA.YRES_EXPDEPHOUR AEXPDEPHOUR,
CA.XCMS_ID ACMSID,
DECODE (CA.xcms_type, 1, CA.xcms_name1 || ' ' || CA.xcms_name2 || ' ' || CA.xcms_name3,  TRIM( DECODE (NVL(CA.xcms_name1, ''), '', '',CA. xcms_name1 || DECODE (NVL( CA.xcms_name3, ''), '', '', ',') || ' ')  || DECODE (NVL (CA.xcms_name3, ''), '', '',CA.xcms_name3  || ' ') || CA.xcms_name2))  AGUESTNAME,
nvl((select sum(YRGL.YRGL_NUMBER) from yrgl where YRGL.YRGL_YDET_ID=DA.YDET_ID),0) AKIDS
 from
ydet DA,yres RA,yrms, xcms CA
where
DA.ydet_id=nvl(RA.yres_current_ydet_id,RA.yres_last_ydet_id) and RA.yres_calcstatus in (3,4,8,2)
and (   (ydet_date<>(select * from fideliodate) and DA.ydet_yrms_id=yrms_id)
     or (ydet_date=(select * from fideliodate) and RA.yres_yrms_id=yrms_id))
--and yrms_id=139
and RA.yres_hasshare=0
and RA.YRES_XCMS_ID=CA.XCMS_ID
union all
-- share resevation, master share
select 
RA.YRES_ID ARESID,
DA.YDET_ADULTNO AADULTNO,
YRMS.YRMS_ID ARMSID,
RA.YRES_CALCSTATUS ACALCSTATUS,
RA.YRES_EXPARRTIME AEXPARRTIME,
RA.YRES_ACTARRTIME AACTARRTIME,
RA.YRES_EXPDEPTIME AEXPDEPTIME,
RA.YRES_ACTDEPTIME AACTDEPTIME,
RA.YRES_EXPARRHOUR AEXPARRHOUR,
RA.YRES_EXPDEPHOUR AEXPDEPHOUR,
CA.XCMS_ID ACMSID,
DECODE (CA.xcms_type, 1, CA.xcms_name1 || ' ' || CA.xcms_name2 || ' ' || CA.xcms_name3,  TRIM( DECODE (NVL(CA.xcms_name1, ''), '', '',CA. xcms_name1 || DECODE (NVL( CA.xcms_name3, ''), '', '', ',') || ' ')  || DECODE (NVL (CA.xcms_name3, ''), '', '',CA.xcms_name3  || ' ') || CA.xcms_name2))  AGUESTNAME,
nvl((select sum(YRGL.YRGL_NUMBER) from yrgl where YRGL.YRGL_YDET_ID=DA.YDET_ID),0) AKIDS
 from
ydet DA,yres RA,yrms, xcms CA
where
DA.ydet_id=nvl(RA.yres_current_ydet_id,RA.yres_last_ydet_id) and RA.yres_calcstatus in (3,4,8,2)
and (   (ydet_date<>(select * from fideliodate) and DA.ydet_yrms_id=yrms_id)
     or (ydet_date=(select * from fideliodate) and RA.yres_yrms_id=yrms_id))
and RA.yres_hasshare=1
and RA.yres_sharetype=1
and RA.YRES_XCMS_ID=CA.XCMS_ID
union all
--share Resevation no master, so max values are taken
select
RA.YRES_ID ARESID,
SR.YDET_ADULTNO_S AADULTNO,
SR.YRMS_ID_S ARMSID,
RA.YRES_CALCSTATUS ACALCSTATUS,
RA.YRES_EXPARRTIME AEXPARRTIME,
RA.YRES_ACTARRTIME AACTARRTIME,
RA.YRES_EXPDEPTIME AEXPDEPTIME,
RA.YRES_ACTDEPTIME AACTDEPTIME,
RA.YRES_EXPARRHOUR AEXPARRHOUR,
RA.YRES_EXPDEPHOUR AEXPDEPHOUR,
CA.XCMS_ID ACMSID,
DECODE (CA.xcms_type, 1, CA.xcms_name1 || ' ' || CA.xcms_name2 || ' ' || CA.xcms_name3,  TRIM( DECODE (NVL(CA.xcms_name1, ''), '', '',CA. xcms_name1 || DECODE (NVL( CA.xcms_name3, ''), '', '', ',') || ' ')  || DECODE (NVL (CA.xcms_name3, ''), '', '',CA.xcms_name3  || ' ') || CA.xcms_name2))  AGUESTNAME,
SR.KIDS_S AKIDS
from
(
select 
max(RAS.yres_id) YRES_ID_S,
sum(DA.ydet_adultno) YDET_ADULTNO_S,
yrms_id YRMS_ID_S,
sum(nvl((select sum(YRGL.YRGL_NUMBER) from yrgl where YRGL.YRGL_YDET_ID=DA.YDET_ID),0)) KIDS_S
 from
ydet DA,yres RAS,yrms
where
Da.ydet_id=nvl(RAS.yres_current_ydet_id,RAS.yres_last_ydet_id) and RAS.yres_calcstatus in (3,4,8,2)
and (   (ydet_date<>(select * from fideliodate) and DA.ydet_yrms_id=yrms_id)
     or (ydet_date=(select * from fideliodate) and RAS.yres_yrms_id=yrms_id))
and RAS.yres_hasshare=1
and RAS.yres_sharetype=0
and DA.ydet_yrms_id is not null
group by
yrms_id) SR ,yres RA, xcms CA
where SR.YRES_ID_S=RA.YRES_ID
and RA.YRES_XCMS_ID=CA.XCMS_ID
) ARES,
(--Next Res:
--no sharer
select 
RA.YRES_ID NRESID,
DA.YDET_ADULTNO NADULTNO,
YRMS.YRMS_ID NRMSID,
RA.YRES_CALCSTATUS NCALCSTATUS,
RA.YRES_EXPARRTIME NEXPARRTIME,
RA.YRES_ACTARRTIME NACTARRTIME,
RA.YRES_EXPDEPTIME NEXPDEPTIME,
RA.YRES_ACTDEPTIME NACTDEPTIME,
RA.YRES_EXPARRHOUR NEXPARRHOUR,
RA.YRES_EXPDEPHOUR NEXPDEPHOUR,
CA.XCMS_ID NCMSID,
DECODE (CA.xcms_type, 1, CA.xcms_name1 || ' ' || CA.xcms_name2 || ' ' || CA.xcms_name3,  TRIM( DECODE (NVL(CA.xcms_name1, ''), '', '',CA. xcms_name1 || DECODE (NVL( CA.xcms_name3, ''), '', '', ',') || ' ')  || DECODE (NVL (CA.xcms_name3, ''), '', '',CA.xcms_name3  || ' ') || CA.xcms_name2))  NGUESTNAME,
nvl((select sum(YRGL.YRGL_NUMBER) from yrgl where YRGL.YRGL_YDET_ID=DA.YDET_ID),0) NKIDS
 from
ydet DA,yres RA,yrms, xcms CA
where
DA.ydet_id=nvl(RA.yres_current_ydet_id,RA.yres_last_ydet_id) 
and (   RA.yres_calcstatus in (1)
     or (RA.yres_calcstatus in (3) and ydet_yrms_id<>yres_yrms_id)) 
and DA.ydet_yrms_id=yrms_id
--and yrms_id=139
and RA.yres_hasshare=0
and RA.YRES_XCMS_ID=CA.XCMS_ID
union all
-- share resevation, master share
select 
RA.YRES_ID NRESID,
DA.YDET_ADULTNO NADULTNO,
YRMS.YRMS_ID NRMSID,
RA.YRES_CALCSTATUS NCALCSTATUS,
RA.YRES_EXPARRTIME NEXPARRTIME,
RA.YRES_ACTARRTIME NACTARRTIME,
RA.YRES_EXPDEPTIME NEXPDEPTIME,
RA.YRES_ACTDEPTIME NACTDEPTIME,
RA.YRES_EXPARRHOUR NEXPARRHOUR,
RA.YRES_EXPDEPHOUR NEXPDEPHOUR,
CA.XCMS_ID NCMSID,
DECODE (CA.xcms_type, 1, CA.xcms_name1 || ' ' || CA.xcms_name2 || ' ' || CA.xcms_name3,  TRIM( DECODE (NVL(CA.xcms_name1, ''), '', '',CA. xcms_name1 || DECODE (NVL( CA.xcms_name3, ''), '', '', ',') || ' ')  || DECODE (NVL (CA.xcms_name3, ''), '', '',CA.xcms_name3  || ' ') || CA.xcms_name2))  NGUESTNAME,
nvl((select sum(YRGL.YRGL_NUMBER) from yrgl where YRGL.YRGL_YDET_ID=DA.YDET_ID),0) NKIDS
 from
ydet DA,yres RA,yrms, xcms CA
where
DA.ydet_id=nvl(RA.yres_current_ydet_id,RA.yres_last_ydet_id) 
and (   RA.yres_calcstatus in (1)
     or (RA.yres_calcstatus in (3) and ydet_yrms_id<>yres_yrms_id)) 
and DA.ydet_yrms_id=yrms_id
and RA.yres_hasshare=1
and RA.yres_sharetype=1
and RA.YRES_XCMS_ID=CA.XCMS_ID
union all
--share Resevation no master, so max values are taken
select
RA.YRES_ID NRESID,
SR.YDET_ADULTNO_S NADULTNO,
SR.YRMS_ID_S NRMSID,
RA.YRES_CALCSTATUS NCALCSTATUS,
RA.YRES_EXPARRTIME NEXPARRTIME,
RA.YRES_ACTARRTIME NACTARRTIME,
RA.YRES_EXPDEPTIME NEXPDEPTIME,
RA.YRES_ACTDEPTIME NACTDEPTIME,
RA.YRES_EXPARRHOUR NEXPARRHOUR,
RA.YRES_EXPDEPHOUR NEXPDEPHOUR,
CA.XCMS_ID NCMSID,
DECODE (CA.xcms_type, 1, CA.xcms_name1 || ' ' || CA.xcms_name2 || ' ' || CA.xcms_name3,  TRIM( DECODE (NVL(CA.xcms_name1, ''), '', '',CA. xcms_name1 || DECODE (NVL( CA.xcms_name3, ''), '', '', ',') || ' ')  || DECODE (NVL (CA.xcms_name3, ''), '', '',CA.xcms_name3  || ' ') || CA.xcms_name2)) NGUESTNAME,
SR.KIDS_S NKIDS
from
(
select 
max(RAS.yres_id) YRES_ID_S,
sum(DA.ydet_adultno) YDET_ADULTNO_S,
DA.ydet_yrms_id YRMS_ID_S,
sum(nvl((select sum(YRGL.YRGL_NUMBER) from yrgl where YRGL.YRGL_YDET_ID=DA.YDET_ID),0)) KIDS_S
 from
ydet DA,yres RAS
where
Da.ydet_id=nvl(RAS.yres_current_ydet_id,RAS.yres_last_ydet_id) 
and (   RAS.yres_calcstatus in (1)
     or (RAS.yres_calcstatus in (3) and ydet_yrms_id<>yres_yrms_id)) 
and RAS.yres_hasshare=1
and RAS.yres_sharetype=0
and DA.ydet_yrms_id is not null
group by
DA.ydet_yrms_id) SR ,yres RA, xcms CA
where SR.YRES_ID_S=RA.YRES_ID
and RA.YRES_XCMS_ID=CA.XCMS_ID) NRES
where
YRMS.YRMS_YCAT_ID=YCAT.YCAT_ID
and YRMS.YRMS_YHKS_ID=YHKS.YHKS_ID
and YRMS.YRMS_ID=ARES.ARMSID(+)
and YRMS.YRMS_ID=NRES.NRMSID(+)
and V8_sys_fideliodate between YRMS.YRMS_VALIDFROM and YRMS.yrms_validuntil
order by YRMS.YRMS_WALKORDER;
