--TODO 20087

create or replace procedure switch_paymentterms is
begin  
  null;	

  execute immediate ('ALTER TABLE PAYMENTTERMS
      modify CONSTRAINT PaymentTermType_valid1 disable');

  update paymentterms p
  set p.paymenttermtype = -1
  where p.paymenttermtype = 1
  and p.timestamp < (select sqlscript.createddate from sqlscript where sqlscript.scriptname = 'Script_08.03.00.40.sql');

  update paymentterms p
  set p.paymenttermtype = 1
  where p.paymenttermtype = 2
  and p.timestamp < (select sqlscript.createddate from sqlscript where sqlscript.scriptname = 'Script_08.03.00.40.sql');

  update paymentterms p
  set p.paymenttermtype = 2
  where p.paymenttermtype = -1
  and p.timestamp < (select sqlscript.createddate from sqlscript where sqlscript.scriptname = 'Script_08.03.00.40.sql');

  execute immediate ('ALTER TABLE PAYMENTTERMS
      modify CONSTRAINT PaymentTermType_valid1 enable');
exception
  when others then 
       rollback;
       execute immediate ('ALTER TABLE PAYMENTTERMS
          modify CONSTRAINT PaymentTermType_valid1 enable');
       raise;    
end switch_paymentterms;
/

execute switch_paymentterms;

drop procedure switch_paymentterms;
  


