--UPDATE SCRIPT ONLY NEEDED FOR HOTELS WORKING WITH FOREIGN RATE CODES AND PROMOTIONS

update ylpr 
set ylpr_amount=
   ylpr_foreignamount
  *(select yres_contract_exchrate 
    from yres,ydet 
    where yres_id=ydet_yres_id 
    and ylpr_ydet_id=ydet_id
   )
where exists (select 1 
              from yres,ydet 
              where yres_id=ydet_yres_id 
              and ydet_id=ylpr_ydet_id 
              and nvl(yres_exch_updatetype,0)=0
              and yres_contract_zcur_id <> (select wuss_value from wuss where wuss_name='BaseCurrency')
             );

update ydet set ydet_ratediff=(select sum(-ylpr_amount) from ylpr where ylpr_ydet_id=ydet_id)
, ydet_foreignratediff=(select sum(-ylpr_foreignamount) from ylpr where ylpr_ydet_id=ydet_id)
where exists (select 1
              from yres
              where yres_id=ydet_yres_id 
              and nvl(yres_exch_updatetype,0)=0
              and yres_contract_zcur_id <> (select wuss_value from wuss where wuss_name='BaseCurrency')
             ) 
and abs(ydet_ratediff
        +(select sum(ylpr_amount) from ylpr where ylpr_ydet_id=ydet_id)
       )<=0.1; 
